Ask Question
20 May, 07:01

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. 20 May, 10:25
    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?
Find 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 and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers