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.


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

Page 3 of 3 FirstFirst 123
Results 51 to 53 of 53

Thread: Help me with my code (im learning Java)

  1. #51
    Join Date
    Dec 2012
    My Mood
    Thanked 0 Times in 0 Posts

    Default Re: Help me with my code (im learning Java)

    @R0bsterz, I'm going to give you the pseudocode, see if you can follow it and code the program.
    -Create a string of "Sammy"
    -Create a new scanner
    - Print out your greeting
    - Create a string that is equal to what the scanner pick up on the next line.
    - Use conditionals statement to compare the string, with (string.equals())

  2. #52
    Super Moderator pbrockway2's Avatar
    Join Date
    Jan 2012
    Thanked 206 Times in 182 Posts

    Default Re: Help me with my code (im learning Java)

    Hi R0bsterz, I can't understand why you call nextLine() before you tell the user to enter anything. That seems backwards to me: use System.out.println() to tell the user what to enter, and then call uinput.nextLine() to get their input and assign it to uinputvar.

    if (name.equals(name)) {

    This line is a real mystery. Others have said it, but name will always be equal to name, so name.equals(name) will always be true whatever the user enters. There might be some confusion here: when people ask what you meant that line to do they aren't asking about what the overall intended behaviour of the program is (I think we all understand that), but are asking about that particular line and what you intended to compare with what.

    It can be confusing to have to spell everythin out to the computer, but stop and think for a moment. You have declared three variables in that program: uinput, uinputvar and name. Make sure you understand and can explain in a short sentence what each variable represents. "name is the name I am going to compare against", "uinputvar is the ..." etc.


    If you are really stuck with basic Java syntax (and what variables are) or can't understand the questions or suggestions being made here then the place to go to is a good textbook, or some online tutorial. I would guess that few, if any, people will be prepared to actually write the code for you.

    --- Update ---

    Quote Originally Posted by R0bsterz View Post
    i know what a variable is
    i don't fully know how to assign a value to a variable
    A line like "foo=42" assigns the value of 42 to foo, and a more complex line like "foo=bar * baz();" works out the expression on the right and assigns that to foo. So when talk about "assigning" we are just talking about the = operator does.

    i dont know how to call a method
    A line like "foo()" calls the method foo(). A more complicated line like "bar=myObject.foo()" also calls the method foo() - of the myObject object - and then goes on to assign the result to bar. (Notice how the line is read a little backwards: the calling happens first and the assignment second.) When we talk about "calling" a method that's just jargon for "using" the method.

    i dont know how to assign the value that the method returns to a variable...
    (Already dealt with)

  3. #53
    Join Date
    Jan 2013
    My Mood
    Thanked 0 Times in 0 Posts

    Default Re: Help me with my code (im learning Java)

    FIXED, thanks for your help guys =]

Page 3 of 3 FirstFirst 123

Similar Threads

  1. Learning Java
    By jblankinship in forum Member Introductions
    Replies: 1
    Last Post: October 14th, 2012, 04:14 PM
  2. Need some help, learning java!
    By thisguyrighthere in forum Object Oriented Programming
    Replies: 5
    Last Post: June 10th, 2012, 09:41 PM
  3. Learning Java
    By destruxion in forum Member Introductions
    Replies: 1
    Last Post: September 12th, 2011, 03:13 AM
  4. Learning Java
    By jgc1 in forum What's Wrong With My Code?
    Replies: 7
    Last Post: May 6th, 2011, 06:17 PM
  5. Tips or suggestion to learn java
    By tj23 in forum Java Theory & Questions
    Replies: 1
    Last Post: February 2nd, 2009, 05:05 AM

Tags for this Thread