Java break statement with label
public class JavaBreakWithLableExample
{
public static void main(String[] args)
{
int[][] intArray = new
int[][]{{1,2,3,4,5},{10,20,30,40,50}};
boolean blnFound = false;
System.out.println("Searching 30 in two
dimensional int array..");
for(int intOuter=0; intOuter <
intArray.length ; intOuter++)
{
for(int intInner=0; intInner <
intArray[intOuter].length; intInner++)
{
if(intArray[intOuter][intInner] == 30)
{
blnFound = true;
break Outer;
}
}
}
if(blnFound == true)
System.out.println("30 found in the
array");
else
System.out.println("30 not found in the
array");
}
}
Switch Statement
public class SwitchStatementExample
{
public static void main(String[] args)
{
switch(expression)
{
break;
case
value2:
default:
break;
}
for(int i=0; i <= 3 ; i++)
{
switch(i)
{
case 0:
System.out.println("i is 0");
break;
case 1:
System.out.println("i is 1");
break;
case 2:
System.out.println("i is 2");
break;
default:
System.out.println("i is greater than
2");
}
}
}
}
Free Flowing Switch Statement
public class FreeFlowingSwitchExample
{
public static void main(String[] args)
{
int i=0;
switch(i)
{
case 0:
System.out.println("i is 0");
case 1:
System.out.println("i is 1");
case 2:
System.out.println("i is 2");
default:
System.out.println("Free flowing switch
example!");
}
}
}
Nested Switch Statements
public class NestedSwitchExample
{
public static void main(String[] args)
{
int i = 0;
int j = 1;
switch(i)
{
case 0:
switch(j)
{
case 0:
System.out.println("i is 0, j is
0");
break;
case 1:
System.out.println("i is 0, j is
1");
break;
default:
System.out.println("nested default
case!!");
}
break;
default:
System.out.println("No matching case
found!!");
}
}
}
No comments:
Post a Comment