Creating a text based game. I have a method for each of the following: Race, profession, name.
So for instance:

public static void main(String[] args) {
        // TODO code application logic here
        intro();
        name();
        System.out.println("Welcome " + name);
    }

    public static void String name(){
        System.out.println("Enter Name:");
        String name = sc.next();
        return name;
    }

Yet I get an error when using the name variable in my print in main. Why?

Recommended Answers

All 5 Replies

Your method name() is void, so it doesn't return anything.

Actually its not void. Thats a typo in their.

maybe try declaring name = name(); Is it the actual name variable that is causing issues?

String name*

Yup that worked. Thank you!

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.