208k views
2 votes
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.

1 Answer

4 votes

Answer:

if(age<18){

minors+=1;

}

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

adults+=1;

}

else{

seniors+=1;

}

Step-by-step 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;

}

}

}

User Tomas Di Domenico
by
5.4k points