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.

Respuesta :

ijeggs

Answer:

       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;

       }

   }

}