Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

public class PrintBinary { public static void main(String[] args) { // TODO code application logic here Scanner s = new Scanner(System.in); int x = s.nextInt();

public class PrintBinary { public static void main(String[] args) { // TODO code application logic here Scanner s = new Scanner(System.in); int x = s.nextInt(); char choice; System.out.print("Do you want to start? (Y/N): "); choice = s.next().charAt(0); while (true){ if(choice == 'Y' || choice == 'y'){ System.out.print("Enter an integer and I will convert it to binary code: "); x = s.nextInt(); System.out.println("You entered " + x + "."); printBinary(x); } System.out.println("Do you want to continue? (Y/N): "); if(choice == 'N' || choice == 'n'){ break; } } }//end main method public static void printBinary(int x){ String s = " "; while (x>0){ int d = x % 2; x = x/2; if (d == 0){ s = s + "0"; } else { s = s + "1"; } System.out.println(x + " in binary is " + s + "."); } }//end printBinary method }//end class Print Binary

image text in transcribed

----------------------------------------------------------------

output desired

Do you want to start(Y/N): y Enter an integer and I will convert it to binary code: 16 You entered 16. 16 in binary is 10000.

Do you want to continue(Y/N): y Enter an integer and I will convert it to binary code: 123 You entered 123. 123 in binary is 1111011.

Do you want to continue(Y/N): y Enter an integer and I will convert it to binary code: 359 You entered 359. 359 in binary is 101100111.

Do you want to continue(Y/N): y Enter an integer and I will convert it to binary code: 1024 You entered 1024. 1024 in binary is 10000000000.

Do you want to continue(Y/N): n

Can someone help me fix this

Do you want to start? (Y/N): y Enter an integer and I will convert it to binary code: 2 You entered 2 1 in binary is 0 0 in binary is 0l Do you want to continue? ?Y/N) : Enter an integer and I will convert it to binary code: 5 You entered 5 2 in binary is L 1 in binary is 10 0 in binary is 10l Do you want to continue? ?Y/N) : Enter an integer and I will convert it to binary code: 7 You entered 3 in binary is L 1 in binary is 11 0 in binary is 1ll Do you want to continue? (Y/N) Enter an integer and I will convert it to binary code: BUILD STOPPED (total time 1 minutes 30 seconds)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions