i dont know what i'm doing wrong, but if of you can help me it would be of great help :)
// The "Culminating" class.
public class Culminating
static Console c; // The output console
public static void main (String args) throws IOException
c = new Console ();
String questions = new String ;
String answers = new String ;
answers  = "blue";
questions  = "What colour are blueberries?";
InputStreamReader converter = new InputStreamReader (System.in);
BufferedReader in = new BufferedReader (converter);
for (int i = 1 ; i < 6 ; i++)
System.out.println (questions );
guess = c.readString ();
if (guess == answers )
System.out.println ("You're right!");
// Place your program here. 'c' is the output console
} // main method
} // Culminating class
This topic has been locked.
4 replies Latest Post - 2009-02-03T14:31:52Z by SystemAdmin
Pinned topic need help with my code
Answered question This question has been answered.
Unanswered question This question has not been answered yet.
Updated on 2009-02-03T14:31:52Z at 2009-02-03T14:31:52Z by SystemAdmin
Re: need help with my code2009-02-03T14:31:52Z in response to SystemAdmin>> change "if (guess == answers )" with "if (guess.equals(answers)", problem will be solved
>> if you use former, java compares hashcode of 2 strings, and returns false
The former will not compare hashcodes. In fact if it did compare hashcodes, it would return true since .equals(..) returns true. The former compares the address of the references. Since the address of reference 'guess' is not the same as the address of reference 'answere' it returns false.