3-2 SwitchIf

Post date: Jan 27, 2014 4:24:48 PM

package switchif;

import java.util.Scanner;

public class SwitchIf 

{

    public static void main(String[] args) 

    {

            System.out.print("chose one of them 1,2 : ");

            Scanner input=new Scanner(System.in);

            int n=input.nextInt();

            switch(n)

            {

                case 1:

                    System.out.print("Enter your first name :");

                    String first=input.next();

                    System.out.print("Enter your last name :");

                    String last=input.next();

                    System.out.println("your name : "+first+" "+last);

                    break;

                case 2:

                    System.out.print("Enter your age: ");

                    int user_age = input.nextInt();

                    if(user_age >= 13 && user_age <= 19)

                        System.out.println("You are a Teenager.");

                    else

                        System.out.println("You are not a Teenager.");

                    break;

                default: System.out.println("invalid number");

            } 

    }   

}