Ask 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 18 through 64 and adds 1 to the variable seniors if age is 65 or older.

+2
Answers (1)
  1. Today, 13:15
    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?
Find 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 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