Search This Blog

If you like any posts in this blog then click this icon which is present under the post

Monday, 25 July 2011

Program to Demonstrate switch case in Java

import java .io.*;
class switch
{
public static void main(Strings args[])
{
for (int i=o;i<4;i++)
{
switch(i)
{
case 0: if(i<1)
                        System.out.println(+i+”less than”+1);
            case 1: if(i<2)
                        System.out.println(+i+”less than”+2);
case 2: if(i<3)
                        System.out.println(+i+”less than”+3);
case 3: if(i<4)
                        System.out.println(+i+”less than”+4);
}
}
}
}

Output:
0 less than1
0 less than2
0 less than3
0 less than4
1 less than2
1 less than3
1 less than4
2 less than3
2 less than4
3 less than4

No comments:

Post a Comment

Followers