Home / Posts filed under 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
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 **/
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;
}
}
}
/**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);
}
}
/**WAP TO PRINT THE SEQUENCE 2,4,8,6... USING FOR LOOP*/
public class ListEvenNumbers
{
public static void main(String args[])
{
int limit = 50;
for(int i=1; i <= limit; i++;
{
if( i % 2 == 0)
{
System.out.print(i + " ");
}
}
}
}
/** JAVA PROGRAM TO FIND SUM OF ALL INTEGERS BETWEEN 100 & 200 THAT ARE DIVISIBLE BY 7 */
class SumOfDigit
{
public static void main(String args[])
{
int result=0;
for(int i=100;i<=200;i++){
if(i%7==0)
result+=i;
}
System.out.println("Output of Program is : "+result);
}
Its the Simple Java Program contained simple text output.
Java is an Very Interesting language Used In all platforms. almost java is used for backend develop.
Class Simple
{
public static void main(String args[])
{
System.out.println("My First Java Program");
}
}
Output:
My First Java Program