Java Program to take input from user Using Scanner class

  Java Program to take input from user Using Scanner class

 

import java.util.Scanner;
public class UsingScanner {
public static void main (String args[])
{
System.out.println("Enter the no. of times you want to print your string");
Scanner inputfromuser = new Scanner(System.in);
int a = inputfromuser.nextInt();
System.out.println("Enter your string");
Scanner wordinputfromuser = new Scanner(System.in);
String b = wordinputfromuser.nextLine();
int c = 0;
while ( c < a )
{
System.out.println(b);
c += 1;
}
}
}

 Output for taking Input using Scanner class in Java 

 

0 comments:

Post a Comment