Simple Example for Continue Lable in Java



Simple Example for  Continue Lable in JAVA

class continueex
{
 public static void main(String arg[])
 {
 lable1:for(int i=0;i<10;i++)
 {
 if(i%2==0)
 {
 System.out.println("Even Value:"+i);
 continue lable1;
 }
 System.out.println("Odd Value:"+i);
 }
 }
 }

Output

Even Value:0
Odd Value:1
Even Value:2
Odd Value:3
Even Value:4
Odd Value:5
Even Value:6
Odd Value:7
Even Value:8
Odd Value:9

Simple Example for Labled Break in JAVA



Its The Simple Example for Labled Break Topic in Java. 

class Break
{
public static void main(String args[])
{
int i=5;
First:
{
  Second:
  {
     Third:
       {
           System.out.println("Inside the break");
           if(i==5)
           break Second;
           System.out.println("Inside 3 block");
       }
    System.out.println("Inside 2 block");
 }
 System.out.println("Inside 1 block");
}
}
}

OUTPUT:

Inside the break
Inside 1 block


Java Program to find the Fibonacci Sequence



/**Java Program to find the Fibonacci Sequence **/

Change the Count=5 to How Much Fibonacci series you need. Default Program is set to 5

class Fibonacci
{  
public static void main(String args[])  
{    
 int n1=0,n2=1,n3,i,count=5;    
 System.out.print(n1+" "+n2); 
 for(i=2;i<count;++i)
 {    
  n3=n1+n2;    
  System.out.print(" "+n3);    
  n1=n2;    
  n2=n3;    
 }     
}
}  

Simple Java Program to find the factorial of number



/**Java Program to Find the Factorial of the number**/

Just Change the Value of Number=5 to which factorial you want. the program is setted to the factorial of 5. 

class Factorial
{  
 public static void main(String args[])
{  
   int i,fact=1;  
   int number=5;
   for(i=1;i<=number;i++)
{
      fact=fact*i;    
 }
   System.out.println("Factorial of "+number+" is: "+fact);    
}  
}  

Subscribe By Email

Join Our Newsletter

Get All The Latest Updates Delivered Straight Into Your Inbox For Free!

We Respect Your Privacy

Popular Posts