Ask 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 expression. Sample output with input: 17 18 or less

+3
Answers (1)
  1. 17 June, 21:14
    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 & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers