0

I have the following program, and I want to print the appropriate return statement for the numbers given. I am currently getting the error "cannot find symbol variable result, lines 18 & 19"... how do I get it to work, though? I've tried a few different ways, and this is my current method:

import java.awt.Color;
import java.util.Scanner;

public class ReturnColor {

public static void main(String args[]) {


    Scanner kboard = new Scanner(System.in);

    System.out.println("Enter the amount of red:");
    int r = kboard.nextInt();
    System.out.println("Enter the amount of green:");
    int g = kboard.nextInt();
    System.out.println("Enter the amount of blue:");
    int b = kboard.nextInt();

    returnResult = bestMatch(r, g, b);
    System.out.println(returnResult);
}

public static Color bestMatch(int r, int g, int b) {


    if ((r > g) && (r > b))
        return Color.RED;
    if ((g > r) && (g > b))
        return Color.GREEN;
    if ((b > r) && (b > g))
        return Color.BLUE;
    if ((r == g) && (r > b))
        return Color.YELLOW;
    if ((r == b) && (r > g))
        return Color.MAGENTA;
    if ((b == g) && (b > r))
        return Color.CYAN;
    else
        return Color.GRAY;
}

}

Edited by polarbear125

3
Contributors
6
Replies
7
Views
4 Years
Discussion Span
Last Post by polarbear125
Featured Replies
  • 1

    Look at the method that is called. What does it return? Define the variable to be the same type as what the method returns. Read More

0

"cannot find symbol variable result,

Did you post the correct code or error message? I do NOT see any variable named: result in what you posted

Please post the FULL text of the error mesage that shows the source line etc. Your editted version has left off important information.

0

Sorry, was meant to be
cannot find symbol variable returnResult, lines 18 and 19

0

What do I declare it as, though? It's not an int or char, I don't know what to use..

1

Look at the method that is called. What does it return? Define the variable to be the same type as what the method returns.

0

That was an error I made.. disregard that =/

Edited by polarbear125

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.