There's an error regarding the scanner and i'm honestly not sure how to make it work i'm using javac as a compiler, please help me solve this issue, ive been trying for hours

import java.util.*;

public class testing
    public static void main(String[] args)

String forename;
String surname;
String address;
Scanner scanner = new Scanner(system.in);

	System.out.println( "Enter forename" );
	System.out.println( "Enter surname" );
	System.out.println( "Enter address" );

	forename = scanner.nextLine();
	surname = scanner.nextLine();
	address = scanner.nextLine();

	System.out.println( "Name is "+forename);
        System.out.println( "Name is "+surname);
        System.out.println( "address is "+address);

Edited by Dani: Not a code snippet

8 Years
Discussion Span
Last Post by carl9999

And your question is?

I can tell you that the "nextLine" call should come right after the print to which it corresponds, though.

Edited by masijade: n/a


Following up on the previous post, put your scanners after each related print statement. For example:

System.out.println( "Enter forename" );
forename = scanner.nextLine();

Repeat for the others.

Edited by Grn Xtrm: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.