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);
    }
}

Recommended Answers

All 3 Replies

And your question is?

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

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.

i managed to solve it, thanks for taking the time tho :)

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.