how do i scan for n times in java

Solutions on MaxInterview for how do i scan for n times in java by the best coders in the world

showing results for - "how do i scan for n times in java"
Emelie
09 Sep 2016
1//Link: https://www.quora.com/How-do-I-can-get-n-lines-of-text-as-input-from-the-user-in-java
2
3//using Scanner
4
5import java.util.Scanner; 
6public class ScannerDemo 
7{ 
8  public static void main(String args[]) 
9  { 
10     Scanner sc = new Scanner(System.in); 
11     int n; 
12     n=Integer.parseInt(sc.nextLine()); 
13    for(int i=1; i<=n; i++) 
14    {   
15     System.out.print("Enter input:"); 
16     String input = sc.nextLine(); 
17     System.out.println(input); 
18    } 
19  } 
20} 
21