Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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");     } }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote