150. JAVA Program to Print Your Name in n times.
How does this program work?
- In this program your going to learn about how to learn while loop using Java.
Here is the code
//Java program to print name N times using while loop
import java.util.Scanner;public class Name
{
public static void main (String args[] )
{
int loop,n;
String name;
System.out.println("Enter name:");
Scanner obj=new Scanner(System.in);
name=obj.nextLine();
System.out.println("Enter Number times to repeat name");
n=obj.nextInt ();
//Initialization of loop counter
loop=1;while (loop<=n)
{
System.out.println(name);
//Increment
loop++;}
}
}