The template code provided is intended to check whether an integer entered by the user is outside of the range 20-29 (inclusive). If it is outside of this range the program should print a warning and change the number to 25. However, when using De Morgan's law to simplify this code, the programmer has made some mistakes. Can you correct the errors so the code functions as intended? code: Scanner scan = new Scanner(System.In); System.Out.Println("Enter a number in the twenties"); int num = scan.NextInt(); if(num < 20 && num > 30){ System.Out.Println("That's not in the twenties!"); num = 25; } System.Out.Println("Your number is " + num);

Respuesta :

Answer:

Change if(num < 20 && num > 30)

to

if(num < 20 || num > 30)

Explanation:

The code has lots of errors most of which are as a result of case sensitivity of java programming language

The following errors were corrected.

All System.Out.Println were changed to System.out.println

scan.NextInt() was changed to scan.nextInt()

Now to the actual correction that needs to be made;

The programmer's error was in using the conditional statement.

The programmer used if(num < 20 && num > 30) as its condition which means that if num is less tha 20 and at the same time greater than 30

This is impossible because no number is greater than 30 and less than 20 at the same time.

So, the correction made was to change the && (and) to || (or) which means that numbers greater than 30 or less than 20.

This corrects the programmer's mistake

See attachment for complete code

Ver imagen MrRoyal
ACCESS MORE
EDU ACCESS