Ask Question
3 January, 17:20

Write an if/else statement that adds 1 to the variable minors if the variable age is less than 18, adds 1 to the variable adults if age is 18 through 64 and adds 1 to the variable seniors if age is 65 or older.

+3
Answers (1)
  1. 3 January, 18:54
    0
    if (age<18) {

    minors+=1;

    }

    else if (age>18 && age<65) {

    adults+=1;

    }

    else{

    seniors+=1;

    }

    Explanation:

    A java program with the variables created and initialized is given below:

    import java. util. Scanner;

    public class num3 {

    public static void main (String[] args) {

    Scanner in = new Scanner (System. in);

    System. out. println ("Enter Age: ");

    int age = in. nextInt ();

    int minors = 16;

    int adults = 20;

    int seniors = 70;

    if (age<18) {

    minors+=1;

    }

    else if (age>18 && age<65) {

    adults+=1;

    }

    else{

    seniors+=1;

    }

    }

    }
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “Write an if/else statement that adds 1 to the variable minors if the variable age is less than 18, adds 1 to the variable adults if age is ...” 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