Question: The following code contains a logic error: Examine the code and describe a case in which the code would print something that is untrue about

The following code contains a logic error:

Scanner console = new Scanner (System.in); System.out.print (

Examine the code and describe a case in which the code would print something that is untrue about the number that was entered. Explain why. Then correct the logic error in the code.

Scanner console = new Scanner (System.in); System.out.print ("Type a number: "); int number console.nextInt (); if (number % 2 0) { %3D3D if (number % 3 0) { %3D3D System.out.println ("Divisible by 6."); } else { System.out.println ("Odd."); }

Step by Step Solution

3.40 Rating (169 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

The code incorrectly prints that even numbers not divisible by 3 are odd ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Building Java Programs A Back to Basics Approach Questions!