gNerb
0
Q:

how do i scan for n times in java

//Link: https://www.quora.com/How-do-I-can-get-n-lines-of-text-as-input-from-the-user-in-java

//using Scanner

import java.util.Scanner; 
public class ScannerDemo 
{ 
  public static void main(String args[]) 
  { 
     Scanner sc = new Scanner(System.in); 
     int n; 
     n=Integer.parseInt(sc.nextLine()); 
    for(int i=1; i<=n; i++) 
    {   
     System.out.print("Enter input:"); 
     String input = sc.nextLine(); 
     System.out.println(input); 
    } 
  } 
} 
1

New to Communities?

Join the community