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

Perform the same operations as question 54, with the following modification: if

ID: 3659710 • Letter: P

Question

Perform the same operations as question 54, with the following modification: if the word does not represent a valid binary number, the program should keep prompting the user for a new word until a word representing a valid binary number is entered. Here is my code. import java.util.*; public class BinaryNumRR { public static void main(String [] args) { Scanner in=new Scanner(System.in); String input; int i; System.out.print("Enter a binary number: "); input=in.next(); while(!checknumber(input)) { System.out.println(input+" is not a binary number"); System.out.print("Enter a binary number: "); input=in.next(); } if(consecutive(input)) System.out.println(input+" accepted"); else System.out.println(input+" rejected"); } public static boolean checknumber(String input) { int i; char c; for(i=0;i

Explanation / Answer

/*Here I am posting only the void main function after makig the correction*/

/*The remaining part will remain same, replace the previous void main funtion with new one*/

public static void main(String[] args) {
        boolean status;
        Scanner in = new Scanner(System.in);
        String input;
        int i;
        do {
            System.out.print("Enter a binary number: ");
            input = in.next();
            status = checknumber(input);
            if (!checknumber(input)) {
                System.out.println(input + " is not a binary number");
            }
        } while (status == false);

        if (consecutive(input))
            System.out.println(input + " accepted");
        else
            System.out.println(input + " rejected");
    }