Jul 17 2009

Flow Statements-If & Switch

Category: Javaadmin @ 10:31 pm

  • If
public class flow1
{
	public static void main(String[] args)
	{
	int x=15;
	if (x>10)
		{
			System.out.println("x is grater than 10 ");
			System.out.println(x>10);
		}
	else
		{
			System.out.println("x is not grater than 10");
			System.out.println(x>10);
		}
	}
 
}

Result
x is grater than 10
true

  • Switch
public class flow2
{
		public static void main(String[] args)
		{
			int x=2;
			switch (x)
			{
				case 1:
					System.out.println("You have selected num 1");
					break;
				case 2:
					System.out.println("You have selected num 2");
					break;
				case 6:
					System.out.println("You have selected num 6");
					break;
				default:
					System.out.println("You haven't selected any num");
 
			}
 
		}
}

Result

You have selected num 2

Tags: , , , ,

One Response to “Flow Statements-If & Switch”

  1. kasun0777 says:

    Wow.Thanx for the info !!

Leave a Reply