JAVA program to accomplish task using string/string Buffer class

By | June 11, 2017

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('!','*'));	
	}
}

 

Author: rabins

Rabins is CEO of R.S. Softwares Private Limited, a software and IT company in Nepal. He runs Nepal's first Internet of Things (IoT) website. He is the owner of RabinsXP who is constantly working for increasing IoT in Nepal. He also builds Android, iOS and Web Apps and crafts beautiful websites. He is also working with various social services. The main aim of Lamichhane is to digitally empower the citizens of Nepal and make the world spiritually sound better both in terms of technology and personal development. RabinsXP is the internet nickname of Rabins Sharma Lamichhane too.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.