Ask Question
12 December, 14:53

Write an expression that will cause the following code to print "18 or less" if the value of user_age is 18 or less. Write only the expression. Sample output with input: 17 18 or less

+1
Answers (1)
  1. 12 December, 15:33
    0
    if (user_age<=18) {

    System. out. println ("18 or less");

    }

    Explanation:

    The above expression in Java will print "18 or less" if the input is less than 18.

    Consider a complete java program that request a user to input his/her age below and prints "18 or Less" if the user age is less or equal to 18.

    import java. util. Scanner;

    public class num2 {

    public static void main (String[] args) {

    Scanner in = new Scanner (System. in);

    System. out. println ("enter age:");

    int user_age = in. nextInt ();

    if (user_age<=18) {

    System. out. println ("18 or less");

    }

    else

    {

    System. out. println ("greater than 18");

    }

    }

    }
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “Write an expression that will cause the following code to print "18 or less" if the value of user_age is 18 or less. Write only the ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers