Westonci.ca is your trusted source for finding answers to a wide range of questions, backed by a knowledgeable community. Our platform provides a seamless experience for finding precise answers from a network of experienced professionals. Connect with a community of professionals ready to provide precise solutions to your questions quickly and accurately.

Write an expression that will cause the following code to print "less than 18" if the value of userAge is less than 18.
import java.util.Scanner;
public class AgeChecker {
public static void main (String [] args) {
int userAge;
Scanner scnr = new Scanner(System.in);
userAge = scnr.nextInt(); // Program will be tested with values: 18, 19, 20, 21.
if (/* Your solution goes here */) {
System.out.println("less than 18");
}
else {
System.out.println("18 or more");
}
}
}


Sagot :

Answer:

Replace /* Your solution goes here */

with: userAge<18

Explanation:

Required

Complete the code

To complete the code, we simply write an expression that compares userAge and 18

From the question, we are to test if userAge is less than 18.

In C++, less than is written as: <

So, the expression that completes the code is: userAge<18