Tuesday, July 22, 2014

If If Else, Conditional Statement in Java

import java.util.Scanner;
public class abejeroact13 {
public static void main (String[] args) {
Scanner input = new Scanner(System.in);
int a;
System.out.println("Enter Choice between nos. 1 and 2");
a = input.nextInt();
if (a==1)
{
System.out.println("Hi!\n You pressed 1");
}
if (a==2)
{
System.out.println("Hello\n You pressed 2");
}
if (a>2)
{
System.out.println("Good Morning\n You input nos. other than 1 and 2");
}
else if (a<1)
{
System.out.println("Good Morning\n You input nos. other than 1 and 2");
}

}
}

No comments:

Post a Comment