Revise the code below such that the program should ask the user toenter letters
ID: 3615742 • Letter: R
Question
Revise the code below such that the program should ask the user toenter letters then terminate once the user has entered two sameletters consecutively.import java.io.*;
public class WhileDemo {
public static void main(String[] args) throwsException
{
BufferedReader keyIn =new BufferedReader(new InputStreamReader(System.in));
System.out.print("Pleaseenter a character: ");
char first =keyIn.readLine().charAt(0);
System.out.print("Pleaseenter another character: ");
char next =keyIn.readLine().charAt(0);
while (first !=next)
{
System.out.print("Pleaseenter another character: ");
next= keyIn.readLine().charAt(0);
}
System.out.println("DONE");
}
}
Sample Output:
Please enter a character: A
Please enter another character: B
Please enter another character: B
Explanation / Answer
please rate - thanks import java.io.*; public class untitled { public static void main(String[] args) throwsException { BufferedReader keyIn =new BufferedReader(new InputStreamReader(System.in)); System.out.print("Pleaseenter a character: "); char first =keyIn.readLine().charAt(0); System.out.print("Pleaseenter another character: "); char next =keyIn.readLine().charAt(0); while (first !=next) { first=next; System.out.print("Please enter another character: "); next =keyIn.readLine().charAt(0); } System.out.println("DONE"); } }
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.