Member Avatar for philipghu

Hi, it is kind of a beginner's question... I'm trying to read user's input from keyboard. The user types in:

a1 a2 a3
b1 b2 b3
c1 c2 c3
...

in which each line has three integers separated by a space. Every three integers are on the same line.

Scanner in = new Scanner(System.in)
		do{
			if(in.nextLine().equals("\n"))
				break;
			int a= in.nextInt();
			int b=in.nextInt();
			int d=in.nextInt();
			adList[a][b]=d;
		
		}while(true);

I thought when I hit enter to switch to a new line and hit enter again, it should stop reading integers then and gets out of the loop. But it never knows when the input ends.
How can I achieve this by reading in the control character '\n' then end the loop?

Thanks

import java.util.Scanner;

class ClassName{
	public static void main(String[] args){
		Scanner in = new Scanner(System.in);
		System.out.println("Message to user here.");
		String line = in.nextLine();
		//Handle line here
	}
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.