Question

import java.util.Scanner;

public class Fernando {
    public static void main(String[] args) {
        Scanner skype = new Scanner(System.in);
        System.out.print("What is your name ")?
        String n = skype.nextLine(); // This is the line with the error
        System.out.print("\n and how old are you?");
        int y = skype.nextInt();
        displayInfo(n,y);
    }

    public String displayInfo(String name, int age){
        return name +" is "+ age+" years old.";
    }
}

All it says is expected. I don't understand what's wrong at all.

Was it helpful?

Solution

Try changing

System.out.print("What is your name ")?

to:

System.out.println("What is your name?");

This should work, as you have a ? instead of a ;.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top