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 30){
System.out.println("That's not in the twenties!");
num = 25;
}
System.out.println("Your number is " + num);
sample run: Enter a number in the twenties
28
Your number is 28

Respuesta :

import java.util.Scanner;

public class JavaApplication60 {

   

   public static void main(String[] args) {

       Scanner scan = new Scanner(System.in);

       System.out.println("Enter a number in the twenties");

       int num = scan.nextInt();

   if(num >= 30 || num <= 19){

       System.out.println("That's not in the twenties!");

       num = 25;

   }

   System.out.println("Your number is " + num);

   }

}

This is the complete code including the main class and main method. I hope this helps!

Debugging a code involves locating and correcting the errors in a code.

The error in the code segment is: invalid conditional statement

The conditional statement is given as: if (num 30)

The above condition is incorrect, because, there is no comparison operator between num and 30

The correct conditional statement is: if(num >= 30 || num<20)

So, the complete correct program is:

Scanner scan = new Scanner(System.in);

 System.out.println("Enter a number in the twenties");

 int num = scan.nextInt();

 if(num >= 30 || num <20){

     System.out.println("That's not in the twenties!");

     num = 25;

 }

System.out.println("Your number is " + num);

Read more about debugging at:

https://brainly.com/question/23527739

ACCESS MORE