JAVA program to accomplish task using string/string Buffer class

Write a program to Implement a program to accomplish the following task using string/string Buffer class:
i. Accept a password from the user.
ii. Check if password is correct then display “Good”
Else display “Incorrect password”
iii. Append the password with the string “Welcome to Java!!!”
iv. Display the password in reverse order.
v. Replace the character ‘!’ in password with “*” character.

import java.lang.*;
import java.io.*;
class q6String
{
	public static void main(String args[]) throws IOException
	{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String s1 = "!!sspp!!";
		String s2;
		System.out.println ("Enter Password");
		s2 = br.readLine();
		if(s1.compareTo(s2)==0)
		{
			System.out.println ("Good");
		}
		else
		{
			System.out.println ("Password is incorrect");
			System.exit(0);
		}
		String s3 = "Welcome to Java!!!";
		StringBuffer sb = new StringBuffer(s1);
		sb.append(s3);
		System.out.println ("Appended Password = "+sb);
		StringBuffer s4 = new StringBuffer(s1);
		s4=s4.reverse();
		System.out.println ("String in Reverse Order = "+s4);
		System.out.println ("Replaced '!' with '*' = "+s1.replace('!','*'));	
	}
}

 

Rabins Sharma Lamichhane

Rabins Sharma Lamichhane is senior ICT professional who talks about #it, #cloud, #servers, #software, and #innovation. Rabins is also the first initiator of Digital Nepal. Facebook: rabinsxp Instagram: rabinsxp

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *