Programs on For loop, while loop and do-while loop
1. FOR LOOP
public class forloop
{
public static void main(String[] args)
{
for(int i=1;i<=20;i++)
{
System.out.println(i);
}
}
}
2. While LOOP
public class whileloop
{
public static void main(String[] args)
{
int i=1;
while(i<=20){
System.out.println(i);
i++;
}
}
}
3. Do-while Loop
public class dowhileloop
{
public static void main(String[] args)
{
int j=1;
do{
System.out.println(j);
j++;
}while(j<=10);
}
}
Comments
Post a Comment