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.

Results 1 to 2 of 2

Thread: Cant figure this out

  1. #1
    Junior Member
    Join Date
    Apr 2013
    Thanked 0 Times in 0 Posts

    Default Cant figure this out

    okay heres the question

    A method called printResult() that takes an integer representing the final score at a computer game, and a boolean indicating whether the player won or not. If the player won, the method should display the line:
    Player wins with <score> points. Otherwise it should display the line:
    Computer wins with <score> points. where <score> is the value of the integer parameter.

    and heres my code ive done so far

    String printResult(int score, boolean win) {
    if (win = true) {
    return "Player wins with" + score + "points.";
    else {
    return "Computer wins with" + score + "points.";

    can you see why this is wrong?


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Eastern Florida
    Thanked 2,637 Times in 2,587 Posts

    Default Re: Cant figure this out

    Use the == operator for comparing two primitive values.

    Testing a boolean variable equal to true is redundant. The boolean variable itself has the value:
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. hi if u can help me please to figure this how D become result of 1
    By ohad in forum What's Wrong With My Code?
    Replies: 2
    Last Post: April 4th, 2013, 07:35 AM
  2. I can't figure this out! Please help!
    By angyvill85 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: July 2nd, 2012, 03:36 AM
  3. i cannot figure out what's wrong
    By biyuss in forum What's Wrong With My Code?
    Replies: 3
    Last Post: October 17th, 2011, 09:22 PM
  4. [SOLVED] can't figure out..
    By darego in forum What's Wrong With My Code?
    Replies: 6
    Last Post: December 10th, 2010, 02:26 PM
  5. I'm new at this and can't figure it out
    By jaheh06 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: September 22nd, 2010, 08:44 AM