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 6 of 6

Thread: Help with a Java Methods Program

  1. #1
    Junior Member
    Join Date
    Nov 2018
    Location
    Under Ya Mother Bed ;)
    Posts
    5
    My Mood
    Confused
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Help with a Java Methods Program

    ive created a java program that the user enters their name and the program will then print out hello (whatever their name is) and goodbye (whatever their name is). the code i have shown create a program that allows for user input but it will not add the users name after hello or goodbye.

    any help is appreciated.
    indents are correct in my program

    import java.util.Scanner;
    public class HelloGoodbye
    {
    	public static void main(String[] args)
    	{
    		Scanner in = new Scanner(System.in);
    		System.out.print("Enter your name : ");
    		String name = in.nextLine();
    		hello(name);
    		goodbye(name);
    	}
    	static void hello(String name)
    	{ 
    		System.out.println("Hello" + name);
    	}
    	static void goodbye(String name)
    	{ 
    		System.out.println("Goodbye" + name);
    	}
    }

    Screen Shot 2018-11-09 at 22.17.19.png
    Last edited by TheRealFawcett; November 9th, 2018 at 06:00 PM.

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Help with a Java Methods Program

    it will not add the users name after hello or goodbye.
    Can you copy the contents of the command prompt window and paste it here so we can see what you are talking about?

    Please edit your post and wrap your code with code tags:

    [code]
    **YOUR CODE GOES HERE**
    [/code]

    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Nov 2018
    Location
    Under Ya Mother Bed ;)
    Posts
    5
    My Mood
    Confused
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help with a Java Methods Program

    i have done now

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Help with a Java Methods Program

    The code works for me.
    How are you executing the program?

    Add this line following the line where name is being read:
       System.out.println("name="+name+"<");  // show what was read
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Nov 2018
    Location
    Under Ya Mother Bed ;)
    Posts
    5
    My Mood
    Confused
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help with a Java Methods Program

    I ended up getting it working but thank you for the help.

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Help with a Java Methods Program

    I ended up getting it working
    Can you explain what you did to get it working?
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Using methods from one java program in another
    By osric in forum Object Oriented Programming
    Replies: 1
    Last Post: April 10th, 2013, 10:30 AM
  2. Applying Methods to Program
    By Praetorian in forum What's Wrong With My Code?
    Replies: 2
    Last Post: March 2nd, 2013, 11:11 PM
  3. Having trouble writing the methods for this program
    By michael305rodri in forum What's Wrong With My Code?
    Replies: 5
    Last Post: November 1st, 2012, 11:31 PM
  4. Program not compiling + calling methods help
    By alex067 in forum What's Wrong With My Code?
    Replies: 9
    Last Post: September 11th, 2012, 07:41 AM
  5. [SOLVED] Java Beginner: Help with methods and returning values (hailstone program)
    By alf in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 14th, 2010, 06:28 PM

Tags for this Thread