Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 11 of 11

Thread: Beginner Help Runs but has Minor Error!

  1. #1
    Junior Member
    Join Date
    Feb 2013
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Exclamation 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)

    *
     
    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() + "!");
       }
     
    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,623
    Thanks
    50
    Thanked 2,235 Times in 2,207 Posts

    Default Re: Beginner Help Runs but has Minor Error!

    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.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Feb 2013
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default 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

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,623
    Thanks
    50
    Thanked 2,235 Times in 2,207 Posts

    Default 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?
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Feb 2013
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default 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

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,623
    Thanks
    50
    Thanked 2,235 Times in 2,207 Posts

    Default 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?
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member
    Join Date
    Feb 2013
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default 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

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,623
    Thanks
    50
    Thanked 2,235 Times in 2,207 Posts

    Default Re: Beginner Help Runs but has Minor Error!

    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?
    If you don't understand my answer, don't ignore it, ask a question.

  9. #9
    Junior Member
    Join Date
    Feb 2013
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default 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

  10. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,623
    Thanks
    50
    Thanked 2,235 Times in 2,207 Posts

    Default Re: Beginner Help Runs but has Minor Error!

    is there extra information I do not need in this command.
    what command?
    If you don't understand my answer, don't ignore it, ask a question.

  11. The Following User Says Thank You to Norm For This Useful Post:

    laxinnn (February 13th, 2013)

  12. #11
    Junior Member
    Join Date
    Feb 2013
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Beginner Help Runs but has Minor Error!

    program* I'm all good I got it to work thank you

Similar Threads

  1. Need some minor help.
    By XxDarkstarxX in forum What's Wrong With My Code?
    Replies: 58
    Last Post: February 10th, 2013, 09:56 PM
  2. java using textpad. Atm code not having any syntax error but runs funny
    By bukasmayor in forum What's Wrong With My Code?
    Replies: 8
    Last Post: January 28th, 2013, 06:55 AM
  3. no error when compiled but when the program runs .. help this !!!
    By izzahmed in forum What's Wrong With My Code?
    Replies: 5
    Last Post: November 8th, 2011, 07:55 AM
  4. Java vending machine, minor thing.
    By Aprok in forum What's Wrong With My Code?
    Replies: 3
    Last Post: October 5th, 2011, 02:35 PM
  5. [SOLVED] Please help with this... I think I have a minor coding error
    By Leprechaun_hunter in forum What's Wrong With My Code?
    Replies: 5
    Last Post: April 12th, 2011, 08:02 AM

Tags for this Thread