Java Program for String and String Buffer class

Write a Java program to implement a program to accomplish the following task using string / string buffer class :

i. Accept a password from user.
ii. Check if password is correct then display 'Good' else display 'Password is incorrect'
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.



Source Code
import java.lang.*;
import java.io.*;

public class StringActivity {
	
	public static void main(String args[]) throws IOException {
		
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String s1 = "admin!";
		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('!','*'));	
	}
}
Output
Enter Password
admin!
Good
Appended Password = admin!Welcome to Java!!!
String in Reverse Order = !nimda
Replaced '!' with '*' = admin*