//Java program to print name 10 times using do while loop
public class PrintNames
{
public static void main(String args[]){
int loop; //loop counter declaration
final String name="Mike"; //name as constant
loop=1; //initialization of loop counter
do{
System.out.println(name);
loop++; //increment
}while(loop<=10);
}
}
Output
Mike
Mike
Mike
Mike
Mike
Mike
Mike
Mike
Mike
Mike
Programs 2) Print numbers from 1 to N.
//Java program to print numbers from 1 to N
import java.util.Scanner;
public class PrintNumbers
{
public static void main(String args[]){
int loop; //declaration of loop counter
int N;
Scanner SC=new Scanner(System.in);
System.out.print("Enter value of N: ");
N=SC.nextInt();
loop=1;
do{
System.out.print(loop +" ");
loop++;
}while(loop<=N);
}
do while Loop Example in Java
Programs 1) Print your name 10 times.
Output
Mike Mike Mike Mike Mike Mike Mike Mike Mike MikePrograms 2) Print numbers from 1 to N.
Output
need an explanation for this answer? contact us directly to get an explanation for this answer