Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Scanner - nextLine() Problem

807598Mar 16 2006 — edited Oct 17 2007
Hi,

This is killing me, I wrote an extremely simple program to test a much larger issue, but I can't even get the small program correct! Any help would be appreciated.

The program compiles, but when run it skips the last "String job = keyboard.nextLine()" and terminates without accepting inpute. Any ideas? Have I been at this so long I am just overlooking something very simple?
import java.util.Scanner;

public class Testing
{
	public static void main(String[] args)
	{
		Scanner keyboard = new Scanner(System.in);
		
		System.out.println("Name:");
		String name = keyboard.nextLine();
		
		System.out.println("Age:");
		int age = keyboard.nextInt();
		
		System.out.println("Job");
		String job = keyboard.nextLine();
	}
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 14 2007
Added on Mar 16 2006
9 comments
315 views