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;
}

}

Recommended Answers

All 6 Replies

"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.

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

I guess you mean returnResult? You forgot to declare it before you used it.

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

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

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.