178k views
2 votes
Write an if-else statement that checks patronAge. If 55 or greater, print "Senior citizen", otherwise print "Not senior citizen" (without quotes). End with newline.

User Samquo
by
3.0k points

2 Answers

7 votes

Answer:

if (patronAge >= 55 ){

System.out.println("Senior citizen");

}

else{

System.out.println("Not senior citizen");

}

Step-by-step explanation:

User Carloshwa
by
3.3k points
2 votes

Answer:

if(patronAge>=55){

System.out.println("Senior Citizen");

}

else{

System.out.println("Not Senior Citizen");

}

Step-by-step explanation:

Using if and else statements, the condition is checked.

The if statement will evaluate to true if the patronAge is greater or equal to 55 and the statement System.out.println("Senior Citizen"); will be executed.

If this this condition is not true, the else part System.out.println("Not Senior Citizen"); will be executed

A complete Java code snippet is given below that prompts user to enter an age and prints the corresponding message

import java.util.Scanner;

public class num6 {

public static void main(String[] args) {

Scanner in = new Scanner(System.in);

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

int patronAge = in.nextInt();

if(patronAge>=55){

System.out.println("Senior Citizen");

}

else{

System.out.println("Not Senior Citizen");

}

}

}

User Matt Busche
by
3.2k points