1
import java.util.Scanner; 
import java.util.HashMap;

public class Test {
public static void main(String args[]){
    Scanner input= new Scanner(System.in);
    System.out.println("Enter number of employee record do you want");
    int n= input.nextInt(); 
    HashMap<String,String> emprec= new HashMap<>();
    System.out.println("Enter your employee id and salary");
    for(int i=0;i<n;i++){

        String[] s1=input.nextLine().split("\\s+");
        System.out.println("print before taking input");
    }

}
}

I want to read for given n=3 input string but it is not allowing me to do. First print statement is getting executed before taking input using nextLine(), is there any issue with code? But it is allowing me read one less than the required and letting me go to next line on first execution of for loop.

kunal krishna
  • 75
  • 1
  • 8

0 Answers0