Advertisement
jackyhuichunkit

If Statement Example 2

Oct 9th, 2019
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.53 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. class iftest01 {
  4.  
  5.     public static void main(String[] args) {
  6.         int age;
  7.         int gender;
  8.         Scanner sc = new Scanner(System.in);
  9.  
  10.         System.out.print("How old are you?");
  11.         age = sc.nextInt();
  12.         System.out.print("Are you a boy or girl? (Boy=1/Girl=2) ");
  13.         gender = sc.nextInt();
  14.         if (age > 13 && gender==1) {
  15.             System.out.println("Male Adult ticket please.");
  16.         } else {
  17.             if (age < 13 && gender==2){
  18.                 System.out.println("Female Children ticket please.");
  19.             }
  20.         }
  21.     }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement