java For loop programming example

 

For loop programming example

§  Syntax  of for loop:-

1.     for (int i=0;  i<10; i++)    {

//ststement

}

2.    for (int i=0, j=1;  i<10&&>10;  i++,  5--)    {

//ststement

}

Q.p] write a java program to  print 1 to 100 using for loop?

Program:-

class  ForLoopExample   {

public static void main(String  args[])    {

int  x;

for (x=1;  x<=100; x++)    {

System.out.println(x);

}

}
}

Q.p] write a java program to print 2,4,6,8,10,12….96,98,100 using for loop?

Program:-

class  NumberPrint   {

public static void main(String  args[])    {

int  x;

for (x=2;  x<=100; x=x+2)    {

System.out.println(x+ “+”);

}

}
}

Q.p] write a java program to print 2,4,6,8,10,12….96,98,100 using for loop?

Program:-

class  NumberPrint   {

public static void main(String  args[])    {

int  x;

for (x=2;  x<=100; x=x+2)    {

if (x==100)  {

System.out.println(x);

}

else    {

System.out.println(x+ “+”);  }
}

}

}

Q.p] write a java program to print this serices  [2 ….20]to [80…..100] using for loop?

Program:-

class  NumberPrint   {

public static void main(String  args[])    {

int  x;

for (x=2;  x<=100; x++)    {

if (x==100)  {

System.out.println(x);

}

else    {

System.out.println(x+ “+”);  }
}

if  (x==20)  {

X=79;    }

}

}

}


Post a Comment

0 Comments