Beginner Help Runs but has Minor Error!
It runs but repeats the "Enter Name" command twice :(
Please debug and repost thank you!!!!
This program asks for the users name and displays it (Using separate Method)
*
Code Java:
package debugthree3;
import java.util.Scanner;
public class DebugThree3
{
public static void main(String args[])
{
String name;
name = getName();
displayGreeting(name);
}
public static String getName()
{
String name;
Scanner input = new Scanner(System.in);
System.out.print("Enter name ");
name = input.nextLine();
return name;
}
public static void displayGreeting(String name)
{
System.out.println("Hello, " + getName() + "!");
}
}
Re: Beginner Help Runs but has Minor Error!
Quote:
repeats the "Enter Name" command twice
Look at the code and where that message comes from.
How many times is that method called?
Each time the method is called, it will print out the message.
Re: Beginner Help Runs but has Minor Error!
Should I take out the return command.. I am still having a hard time with this one could you explain how you would go about it
Re: Beginner Help Runs but has Minor Error!
Why does the display method call the get method?
Could it use the arg that is passed to it?
Re: Beginner Help Runs but has Minor Error!
Alright that makes sense I fixed that to just name. I still have it asking for the name twice.... I feel like I added something that does not belong
Re: Beginner Help Runs but has Minor Error!
The get method will ask for the name every time it is called.
How many times does the new code call it?
Re: Beginner Help Runs but has Minor Error!
I am very lost..... I continued to switch things with the same result.... only to re start the project and put the code I have in and it wont even ask for the question..... (it was not running the program with the code before) The only thing I have changed is not calling the name method for the last method.... What am I doing wrong :(
Re: Beginner Help Runs but has Minor Error!
Quote:
What am I doing wrong
Sorry, my crystal ball is not working now and I can not see the current version of your program.
Can you post your code so we can see what it is doing?
Re: Beginner Help Runs but has Minor Error!
Strange I restarted Netbeans and it runs my code with no errors and no repeated Question........ But is there extra information I do not need in this command. Just trying to get the basics down and know that I am doing this easy exercise right. I appreciate it
Re: Beginner Help Runs but has Minor Error!
Quote:
is there extra information I do not need in this command.
what command?
Re: Beginner Help Runs but has Minor Error!
program* I'm all good I got it to work thank you