ALL types of LOOPS execution in JAVA .
This is simple java program that will show you how to execute all types of loops in JAVA programming . We explained FOR loop, WHILE loop , DO ---- WHILE loop etc. We have just given code that will explain how to execute various loops In JAVA Programming.
JAVA CODE :)
import java.util.Scanner;
public class Loops
{
public static void main(String[] args)
{
int n,i=1,m,j,p,k;
Scanner sc = new Scanner(System.in);
System.out.print("Enter a number:");
n=sc.nextInt();
//Use of WHILE loop execution
while(i<=10)
{
System.out.println(+n*i);
i++;
}
//DO WHILE loop execution
System.out.print("Enter another number:");
m=sc.nextInt();
do
{
System.out.println(+m*m);
m++;
} while(m<=20);
//FOR loop execution
System.out.print("Enter value of p:");
p=sc.nextInt();
sc.close();
for(j=p;j>=0;j--)
{
for(k=0;k<j;k++)
{
System.out.print("*");
}
System.out.println();
}
}
}
0 Comments