Saturday, April 11, 2009

JAVA PROGRAMMS1

class Bistream{
Void static main (String args[]){
Try{
BufferedInputStream in = new new BufferedInputStream (new FileInputStream("test.txt))); //create an object of fileinputstream type
//and construct BufferedInputStream from it.
Int i;
while((i = in.read ())!= -1)
System.out.Print(i);
in.close();
} catch (exception e){};
}
}


--------------------------------------------------


/* Program to create thread by implementing runnable interface
Author : Team -J
Version : 1.0 */
class Thread1{
static public void main(String[] args){
Thread myThreadA = new Thread(new MyThread1(),"threadA");
Thread myThreadB = new Thread(new MyThread1(),"threadB");
//run the two threads
myThreadA.start();
myThreadB.start();

try{
Thread.currentThread().sleep(1000);
}catch(InterruptedException e){}
//Display info about the main thread
System.out.println(Thread.currentThread());
}
}
class MyThread1 implements Runnable{
public void run(){
for(int i= 0;i <10; i++)
System.out.println(Thread.currentThread());
}
}


-------------------------------------


/* Program to create thread by implementing runnable interface
Author : Team -J
Version : 1.0 */
class Thread2{
static public void main(String[] args){
Thread myThreadA = new Thread(new MyThread2(),"threadA");
Thread myThreadB = new Thread(new MyThread2(),"threadB");
//run the two threads
myThreadA.start();
myThreadB.start();

try{
Thread.currentThread().sleep(1000);
}catch(InterruptedException e){}
//Display info about the main thread
System.out.println(Thread.currentThread());
}
}
class MyThread2 extends Thread{
public void run(){
for(int i= 0;i <10; i++)
System.out.println(Thread.currentThread());
}
}


-------------------------------------------------


/* Program to demonstrate producer/consumer problem
Author : Team -J
Version : 1.0 */
class sharedvar{
int i;
sharedvar(){
i=0;
}
int incvar(){
return i++;
}
int getvar(){
return i;
}
}
class MyThread3A extends Thread{
sharedvar v;
MyThread3A(sharedvar v){
this.v = v;
}
public void run(){
for(int i= 0;i <10; i++)
System.out.println("Value of shared variable "+ v.getvar());
}

}
class MyThread3B extends Thread{
sharedvar v;
MyThread3B(sharedvar v){
this.v = v;
}
public void run(){
for(int i= 0;i <10; i++){
System.out.println("value of shared variable after incrimenting "+v.incvar());
}
}
}
class Thread3{
static public void main(String[] args){
sharedvar v = new sharedvar();
Thread myThread3A = (Thread) new MyThread3A (v);
myThread3A.start();
Thread myThread3B = (Thread) new MyThread3B (v);
myThread3B.start();
}
}

--------------------------------


/* Program to demonstrate producer/consumer problem
Author : Team -J
Version : 1.0 */
class sharedvar{
int i;
sharedvar(){
i=0;
}
int incvar(){
return i++;
}
int getvar(){
return i;
}
}
class MyThread3A extends Thread{
sharedvar v;
MyThread3A(sharedvar v){
this.v = v;
Thread t = new Thread (this,"Thread3A");
t.run();
}
public void run(){
for(int i= 0;i <10; i++)
System.out.println("Value of shared variable "+ v.getvar());
}

}
class MyThread3B extends Thread{
sharedvar v;
MyThread3B(sharedvar v){
this.v = v;
Thread t = new Thread (this,"Thread3B");
t.run();
}
public void run(){
for(int i= 0;i <10; i++){
System.out.println("value of shared variable after incrimenting "+v.incvar());
}
}
}
class Thread3{
static public void main(String[] args){
sharedvar v = new sharedvar();
new MyThread3A (v);
new MyThread3B (v);
}
}

------------------------------------------------------------

/* Program to solve producer/consumer problem
Author : Team -J
Version : 1.0 */
class sharedvar{
int i;
boolean isvarset;
sharedvar(){
i=0;
isvarset=false;
}
synchronized int incvar(){
if( isvarset) //if var is set wait till the other thread reads it
try{
wait();
}catch(InterruptedException e){};
i++;
isvarset = true;
notify();
return i;
}
synchronized int getvar(){
if (!isvarset)try{
wait();
}catch(InterruptedException e){};
isvarset=false;
notify(); //notify the other thread which is waiting to incerment the value
return i;
}
}
//consumer
class MyThread4A extends Thread{
sharedvar v;
MyThread4A(sharedvar v){
this.v = v;
}
public void run(){
for(int i= 0;i <10; i++)
System.out.println("Value of shared variable "+ v.getvar());
}

}
//producer
class MyThread4B extends Thread{
sharedvar v;
MyThread4B(sharedvar v){
this.v = v;
}
public void run(){
for(int i= 0;i <10; i++)
System.out.println("value of shared variable after incrementing "+v.incvar());

}
}
class Thread4{
static public void main(String[] args){
sharedvar v = new sharedvar();
Thread myThread4A = (Thread) new MyThread4A (v);
myThread4A.start();
Thread myThread4B = (Thread) new MyThread4B (v);
myThread4B.start();
}
}

------------------------------------------------------------
/*Version : 1.0
Program to compute x pow 1 /1 ! + x pow 2 / 2! + x pow 3/ 3!
using for construct
Author : Team - J
*/
public class for2
{
public static void main(String args[]){
int i,j,no=3;
float sum=1.0f;
int prod,nopowx;
for(i=1 ; i<5;i++){
//find no power i
nopowx=no;
for(j=1;j
nopowx= nopowx * no;
System.out.println(" power = " + nopowx);
//find factorial of i
prod=1;
for(j=1;j<=i;j++){
prod=prod * j;
}
System.out.println(prod);
sum=sum + nopowx/prod;
}
System.out.println(" sum = " + sum);
}

}


---------------------------------------

/*Version : 1
This program displays a pattern
&&&&&&&&&&&&&&
&&&&&&&&&&&&
&&&&&&&&&&&&&&
&&&&&&&&&&&&
&&&&&&&&&&&&&&
&&&&&&&&&&&&
&&&&&&&&&&&&&&
using for construct
Author : Team - J
*/
public class for3
{
public static void main(String args[]){
int no=10;
int i=1,j;
for(i=1;i<10;i++)
{
if ( (i %2 ) == 0)
System.out.print(" ");
else
System.out.print("&");

for(j=2;j <10;j++)
System.out.print("&");
if ( (i %2 ) == 0)
System.out.print(" ");
else
System.out.print("&");
System.out.println();
}

}
}


-----------------------------------------------------

/*Version : 1
This program uses break and continue
using for construct
Author : Team - J
*/
public class for4
{
public static void main(String args[]){
int no=10;
int i=1,j;
for(i=1;i<10;i++)
{
if ( (i %2 ) == 0)
continue;
/* break;*/
System.out.println(i);
}

}
}


-------------------------------------------------

/*Version : 1
This program uses break and continue
using for construct
Author : Team - J
*/
public class for5
{
public static void main(String args[]){
int no=10;
int i=1,j;
outer_for: for(j=0;j<10;j++){
for(i=1;i<10;i++)
{
if ( (i %2 ) == 0)
/* continue;*/
break outer_for;
System.out.println(i);
}
}

}
}


---------------------------------------


/*Version : 1
This program prints the following pattern
*********
*******
*****
***
*
using for construct
Author : Team - J
*/
public class for6
{
public static void main(String args[]){
int max=9,lines=5,spaces=0;
int i=1,j,k;
for(i=0;i
// print spaces first
for(k=0;k
System.out.print(" ");
for(j=0;j<(max- spaces*2);j++)
System.out.print("*");
spaces++;
System.out.println();
}

}
}



-----------------------------


/*Version : 1.0
This program prints the following pattern
*
***
*****
*******
*********
using for construct
Author : Team - J
*/
public class for7
{
public static void main(String args[]){
int stars=1,lines=5,spaces=5;
int i=1,j,k;
for(i=0;i
// print spaces first
for(k=0;k
System.out.print(" ");
for(j=0;j<(stars);j++)
System.out.print("*");
spaces--;
stars +=2;
System.out.println();
}

}
}


--------------------------------


/*Version : 1
This program prints the following pattern
*
***
*****
*******
*********
using for construct
Author : Team - J
*/
public class for8
{
public static void main(String args[]){
int stars=1,lines=5;
int i=1,j,k;
for(i=0;i
for(j=0;j<(stars);j++)
System.out.print("*");
stars+=2;
System.out.println();
}

}
}


---------------------------------------


/*Version : 1
This program prints the following pattern
using for construct
Author : Team - J
*/
public class for9
{
public static void main(String args[]){
int stars=1,lines=5;
int i=1,j,k;
for(i=0;;i++){
System.out.println(i);
}

}
}


-----------------------------------------

/*Version : 1.0
Program to show how multiple statements can be included in For init
using for construct
Author : Team - J
*/
public class for10
{
public static void main(String args[]){
int i,j,no=3,f=0,k=10;
float sum=1.0f;
int prod,nopowx;
for(i=1,j=0,no=3 ; i<5;i++,f++,k+=99){
//find no power i
nopowx=no;
for(j=1;j
nopowx= nopowx * no;
System.out.println(" power = " + nopowx);
//find factorial of i
prod=1;
for(j=1;j<=i;j++){
prod=prod * j;
}
System.out.println(prod);
sum=sum + nopowx/prod;
}
System.out.println(" sum = " + sum);
System.out.println(i + " " + j + " " + f + " " + k);
}
}


-------------------------------

/*Version : 1.0
Program to show how to use multiple expression statements in For init
using for construct
Author : Team - J
*/
public class formultiexp
{
public static void main(String args[]){
int i,j,no=3,f=0,k=10;
float sum=1.0f;
int prod,nopowx;
for(i=1,j=0,no=3,System.out.println("in For init") ; i<5;i++,f++,k+=99,System.out.println("in For update"),System.out.println("in For update2")){
System.out.println("in For body");
}

}
}


----------------------------------------------------


/*Version : 1
Program using for construct
1+1/1!+1/2!+1/3!+1/4!
Author : Team - J
*/
public class forone
{
public static void main(String args[]){
int i,j,no;
float sum=1.0f;
int prod;
for(i=1 ; i<5;i++){
//find factorial of i
prod=1;
for(j=1;j<=i;j++){
prod=prod * j;

}
System.out.println(prod);
sum=sum + 1.0F/prod;
}
System.out.println(" sum = " + sum);
}
}


---------------------------

ForStatement:
for ( ForInit opt ; Expression opt ; ForUpdate opt )
Statement | Block of Statements

ForInit:
StatementExpressionList
LocalVariableDeclaration
ForUpdate:
StatementExpressionList
StatementExpressionList:
StatementExpression
StatementExpressionList , StatementExpression

---------------------------------------------



/*Version : 1.0
Program to show how to use labled continue
using for construct
Author : Team - J
*/
public class lablecontinuefor
{
public static void main(String args[]){
int i,j,no=3,f=0,k=10;
float sum=1.0f;
lab1:
System.out.println(" lable one");
//lab1:
//System.out.println(" lable one second time");
int prod,nopowx;

lab1:
//while(true){
//System.out.println(" in while");
lab2:
for(i=1; i<3;i++){

System.out.println(" value of i = " +i);
lab3:
for(j=1;j<=4;j++){
System.out.println(" value of j = " + j);
if( j ==1)
continue lab3;
System.out.println(" After break lab3");
if( j ==2)
continue lab3;
System.out.println(" After break lab3 ..");
if( j ==3)
continue lab1;
System.out.println(" After break lab1");
}
}
//}

}
}


--------------------------------------------


/*Version : 1.0
Program to show how to use labled break
using for construct
Author : Team - J
*/
public class lablefor
{
public static void main(String args[]){
int i,j,no=3,f=0,k=10;
float sum=1.0f;
lab1:
System.out.println(" lable one");
//lab1:
//System.out.println(" lable one second time");
int prod,nopowx;

lab1:
while(true){
System.out.println(" in while");
lab2:
for(i=1; i<3;i++){

System.out.println(" value of i = " +i);
lab3:
for(j=1;j<=4;j++){
System.out.println(" value of j = " + j);
if( j ==1)
break lab3;
System.out.println(" After break lab3");
if( j ==2)
break lab3;
System.out.println(" After break lab2");
if( j ==3)
break lab1;
System.out.println(" After break lab1");
}
}
}

}
}

---------------------------------------------

JAVA3
/*Version : 1.0
Program to compute x pow 1 /1 ! + x pow 2 / 2! + x pow 3/ 3!
using for construct
Author : Team - J
*/
public class for2
{
public static void main(String args[]){
int i,j,no=3;
float sum=1.0f;
int prod,nopowx;
for(i=1 ; i<5;i++){
//find no power i
nopowx=no;
for(j=1;j
nopowx= nopowx * no;
System.out.println(" power = " + nopowx);
//find factorial of i
prod=1;
for(j=1;j<=i;j++){
prod=prod * j;
}
System.out.println(prod);
sum=sum + nopowx/prod;
}
System.out.println(" sum = " + sum);
}

}


---------------------------------------

/*Version : 1
This program displays a pattern
&&&&&&&&&&&&&&
&&&&&&&&&&&&
&&&&&&&&&&&&&&
&&&&&&&&&&&&
&&&&&&&&&&&&&&
&&&&&&&&&&&&
&&&&&&&&&&&&&&
using for construct
Author : Team - J
*/
public class for3
{
public static void main(String args[]){
int no=10;
int i=1,j;
for(i=1;i<10;i++)
{
if ( (i %2 ) == 0)
System.out.print(" ");
else
System.out.print("&");

for(j=2;j <10;j++)
System.out.print("&");
if ( (i %2 ) == 0)
System.out.print(" ");
else
System.out.print("&");
System.out.println();
}

}
}


-----------------------------------------------------

/*Version : 1
This program uses break and continue
using for construct
Author : Team - J
*/
public class for4
{
public static void main(String args[]){
int no=10;
int i=1,j;
for(i=1;i<10;i++)
{
if ( (i %2 ) == 0)
continue;
/* break;*/
System.out.println(i);
}

}
}


-------------------------------------------------

/*Version : 1
This program uses break and continue
using for construct
Author : Team - J
*/
public class for5
{
public static void main(String args[]){
int no=10;
int i=1,j;
outer_for: for(j=0;j<10;j++){
for(i=1;i<10;i++)
{
if ( (i %2 ) == 0)
/* continue;*/
break outer_for;
System.out.println(i);
}
}

}
}


---------------------------------------


/*Version : 1
This program prints the following pattern
*********
*******
*****
***
*
using for construct
Author : Team - J
*/
public class for6
{
public static void main(String args[]){
int max=9,lines=5,spaces=0;
int i=1,j,k;
for(i=0;i
// print spaces first
for(k=0;k
System.out.print(" ");
for(j=0;j<(max- spaces*2);j++)
System.out.print("*");
spaces++;
System.out.println();
}

}
}



-----------------------------


/*Version : 1.0
This program prints the following pattern
*
***
*****
*******
*********
using for construct
Author : Team - J
*/
public class for7
{
public static void main(String args[]){
int stars=1,lines=5,spaces=5;
int i=1,j,k;
for(i=0;i
// print spaces first
for(k=0;k
System.out.print(" ");
for(j=0;j<(stars);j++)
System.out.print("*");
spaces--;
stars +=2;
System.out.println();
}

}
}


--------------------------------


/*Version : 1
This program prints the following pattern
*
***
*****
*******
*********
using for construct
Author : Team - J
*/
public class for8
{
public static void main(String args[]){
int stars=1,lines=5;
int i=1,j,k;
for(i=0;i
for(j=0;j<(stars);j++)
System.out.print("*");
stars+=2;
System.out.println();
}

}
}


---------------------------------------


/*Version : 1
This program prints the following pattern
using for construct
Author : Team - J
*/
public class for9
{
public static void main(String args[]){
int stars=1,lines=5;
int i=1,j,k;
for(i=0;;i++){
System.out.println(i);
}

}
}


-----------------------------------------

/*Version : 1.0
Program to show how multiple statements can be included in For init
using for construct
Author : Team - J
*/
public class for10
{
public static void main(String args[]){
int i,j,no=3,f=0,k=10;
float sum=1.0f;
int prod,nopowx;
for(i=1,j=0,no=3 ; i<5;i++,f++,k+=99){
//find no power i
nopowx=no;
for(j=1;j
nopowx= nopowx * no;
System.out.println(" power = " + nopowx);
//find factorial of i
prod=1;
for(j=1;j<=i;j++){
prod=prod * j;
}
System.out.println(prod);
sum=sum + nopowx/prod;
}
System.out.println(" sum = " + sum);
System.out.println(i + " " + j + " " + f + " " + k);
}
}


-------------------------------

/*Version : 1.0
Program to show how to use multiple expression statements in For init
using for construct
Author : Team - J
*/
public class formultiexp
{
public static void main(String args[]){
int i,j,no=3,f=0,k=10;
float sum=1.0f;
int prod,nopowx;
for(i=1,j=0,no=3,System.out.println("in For init") ; i<5;i++,f++,k+=99,System.out.println("in For update"),System.out.println("in For update2")){
System.out.println("in For body");
}

}
}


----------------------------------------------------


/*Version : 1
Program using for construct
1+1/1!+1/2!+1/3!+1/4!
Author : Team - J
*/
public class forone
{
public static void main(String args[]){
int i,j,no;
float sum=1.0f;
int prod;
for(i=1 ; i<5;i++){
//find factorial of i
prod=1;
for(j=1;j<=i;j++){
prod=prod * j;

}
System.out.println(prod);
sum=sum + 1.0F/prod;
}
System.out.println(" sum = " + sum);
}
}


---------------------------

ForStatement:
for ( ForInit opt ; Expression opt ; ForUpdate opt )
Statement | Block of Statements

ForInit:
StatementExpressionList
LocalVariableDeclaration
ForUpdate:
StatementExpressionList
StatementExpressionList:
StatementExpression
StatementExpressionList , StatementExpression

---------------------------------------------



/*Version : 1.0
Program to show how to use labled continue
using for construct
Author : Team - J
*/
public class lablecontinuefor
{
public static void main(String args[]){
int i,j,no=3,f=0,k=10;
float sum=1.0f;
lab1:
System.out.println(" lable one");
//lab1:
//System.out.println(" lable one second time");
int prod,nopowx;

lab1:
//while(true){
//System.out.println(" in while");
lab2:
for(i=1; i<3;i++){

System.out.println(" value of i = " +i);
lab3:
for(j=1;j<=4;j++){
System.out.println(" value of j = " + j);
if( j ==1)
continue lab3;
System.out.println(" After break lab3");
if( j ==2)
continue lab3;
System.out.println(" After break lab3 ..");
if( j ==3)
continue lab1;
System.out.println(" After break lab1");
}
}
//}

}
}


--------------------------------------------


/*Version : 1.0
Program to show how to use labled break
using for construct
Author : Team - J
*/
public class lablefor
{
public static void main(String args[]){
int i,j,no=3,f=0,k=10;
float sum=1.0f;
lab1:
System.out.println(" lable one");
//lab1:
//System.out.println(" lable one second time");
int prod,nopowx;

lab1:
while(true){
System.out.println(" in while");
lab2:
for(i=1; i<3;i++){

System.out.println(" value of i = " +i);
lab3:
for(j=1;j<=4;j++){
System.out.println(" value of j = " + j);
if( j ==1)
break lab3;
System.out.println(" After break lab3");
if( j ==2)
break lab3;
System.out.println(" After break lab2");
if( j ==3)
break lab1;
System.out.println(" After break lab1");
}
}
}

}
}

---------------------------------------------

JAVA3
/*Version : 1.0
Program to compute x pow 1 /1 ! + x pow 2 / 2! + x pow 3/ 3!
using for construct
Author : Team - J
*/
public class for2
{
public static void main(String args[]){
int i,j,no=3;
float sum=1.0f;
int prod,nopowx;
for(i=1 ; i<5;i++){
//find no power i
nopowx=no;
for(j=1;j
nopowx= nopowx * no;
System.out.println(" power = " + nopowx);
//find factorial of i
prod=1;
for(j=1;j<=i;j++){
prod=prod * j;
}
System.out.println(prod);
sum=sum + nopowx/prod;
}
System.out.println(" sum = " + sum);
}

}


---------------------------------------

/*Version : 1
This program displays a pattern
&&&&&&&&&&&&&&
&&&&&&&&&&&&
&&&&&&&&&&&&&&
&&&&&&&&&&&&
&&&&&&&&&&&&&&
&&&&&&&&&&&&
&&&&&&&&&&&&&&
using for construct
Author : Team - J
*/
public class for3
{
public static void main(String args[]){
int no=10;
int i=1,j;
for(i=1;i<10;i++)
{
if ( (i %2 ) == 0)
System.out.print(" ");
else
System.out.print("&");

for(j=2;j <10;j++)
System.out.print("&");
if ( (i %2 ) == 0)
System.out.print(" ");
else
System.out.print("&");
System.out.println();
}

}
}


-----------------------------------------------------

/*Version : 1
This program uses break and continue
using for construct
Author : Team - J
*/
public class for4
{
public static void main(String args[]){
int no=10;
int i=1,j;
for(i=1;i<10;i++)
{
if ( (i %2 ) == 0)
continue;
/* break;*/
System.out.println(i);
}

}
}


-------------------------------------------------

/*Version : 1
This program uses break and continue
using for construct
Author : Team - J
*/
public class for5
{
public static void main(String args[]){
int no=10;
int i=1,j;
outer_for: for(j=0;j<10;j++){
for(i=1;i<10;i++)
{
if ( (i %2 ) == 0)
/* continue;*/
break outer_for;
System.out.println(i);
}
}

}
}


---------------------------------------


/*Version : 1
This program prints the following pattern
*********
*******
*****
***
*
using for construct
Author : Team - J
*/
public class for6
{
public static void main(String args[]){
int max=9,lines=5,spaces=0;
int i=1,j,k;
for(i=0;i
// print spaces first
for(k=0;k
System.out.print(" ");
for(j=0;j<(max- spaces*2);j++)
System.out.print("*");
spaces++;
System.out.println();
}

}
}



-----------------------------


/*Version : 1.0
This program prints the following pattern
*
***
*****
*******
*********
using for construct
Author : Team - J
*/
public class for7
{
public static void main(String args[]){
int stars=1,lines=5,spaces=5;
int i=1,j,k;
for(i=0;i
// print spaces first
for(k=0;k
System.out.print(" ");
for(j=0;j<(stars);j++)
System.out.print("*");
spaces--;
stars +=2;
System.out.println();
}

}
}


--------------------------------


/*Version : 1
This program prints the following pattern
*
***
*****
*******
*********
using for construct
Author : Team - J
*/
public class for8
{
public static void main(String args[]){
int stars=1,lines=5;
int i=1,j,k;
for(i=0;i
for(j=0;j<(stars);j++)
System.out.print("*");
stars+=2;
System.out.println();
}

}
}


---------------------------------------


/*Version : 1
This program prints the following pattern
using for construct
Author : Team - J
*/
public class for9
{
public static void main(String args[]){
int stars=1,lines=5;
int i=1,j,k;
for(i=0;;i++){
System.out.println(i);
}

}
}


-----------------------------------------

/*Version : 1.0
Program to show how multiple statements can be included in For init
using for construct
Author : Team - J
*/
public class for10
{
public static void main(String args[]){
int i,j,no=3,f=0,k=10;
float sum=1.0f;
int prod,nopowx;
for(i=1,j=0,no=3 ; i<5;i++,f++,k+=99){
//find no power i
nopowx=no;
for(j=1;j
nopowx= nopowx * no;
System.out.println(" power = " + nopowx);
//find factorial of i
prod=1;
for(j=1;j<=i;j++){
prod=prod * j;
}
System.out.println(prod);
sum=sum + nopowx/prod;
}
System.out.println(" sum = " + sum);
System.out.println(i + " " + j + " " + f + " " + k);
}
}


-------------------------------

/*Version : 1.0
Program to show how to use multiple expression statements in For init
using for construct
Author : Team - J
*/
public class formultiexp
{
public static void main(String args[]){
int i,j,no=3,f=0,k=10;
float sum=1.0f;
int prod,nopowx;
for(i=1,j=0,no=3,System.out.println("in For init") ; i<5;i++,f++,k+=99,System.out.println("in For update"),System.out.println("in For update2")){
System.out.println("in For body");
}

}
}


----------------------------------------------------


/*Version : 1
Program using for construct
1+1/1!+1/2!+1/3!+1/4!
Author : Team - J
*/
public class forone
{
public static void main(String args[]){
int i,j,no;
float sum=1.0f;
int prod;
for(i=1 ; i<5;i++){
//find factorial of i
prod=1;
for(j=1;j<=i;j++){
prod=prod * j;

}
System.out.println(prod);
sum=sum + 1.0F/prod;
}
System.out.println(" sum = " + sum);
}
}


---------------------------

ForStatement:
for ( ForInit opt ; Expression opt ; ForUpdate opt )
Statement | Block of Statements

ForInit:
StatementExpressionList
LocalVariableDeclaration
ForUpdate:
StatementExpressionList
StatementExpressionList:
StatementExpression
StatementExpressionList , StatementExpression

---------------------------------------------



/*Version : 1.0
Program to show how to use labled continue
using for construct
Author : Team - J
*/
public class lablecontinuefor
{
public static void main(String args[]){
int i,j,no=3,f=0,k=10;
float sum=1.0f;
lab1:
System.out.println(" lable one");
//lab1:
//System.out.println(" lable one second time");
int prod,nopowx;

lab1:
//while(true){
//System.out.println(" in while");
lab2:
for(i=1; i<3;i++){

System.out.println(" value of i = " +i);
lab3:
for(j=1;j<=4;j++){
System.out.println(" value of j = " + j);
if( j ==1)
continue lab3;
System.out.println(" After break lab3");
if( j ==2)
continue lab3;
System.out.println(" After break lab3 ..");
if( j ==3)
continue lab1;
System.out.println(" After break lab1");
}
}
//}

}
}


--------------------------------------------


/*Version : 1.0
Program to show how to use labled break
using for construct
Author : Team - J
*/
public class lablefor
{
public static void main(String args[]){
int i,j,no=3,f=0,k=10;
float sum=1.0f;
lab1:
System.out.println(" lable one");
//lab1:
//System.out.println(" lable one second time");
int prod,nopowx;

lab1:
while(true){
System.out.println(" in while");
lab2:
for(i=1; i<3;i++){

System.out.println(" value of i = " +i);
lab3:
for(j=1;j<=4;j++){
System.out.println(" value of j = " + j);
if( j ==1)
break lab3;
System.out.println(" After break lab3");
if( j ==2)
break lab3;
System.out.println(" After break lab2");
if( j ==3)
break lab1;
System.out.println(" After break lab1");
}
}
}

}
}