I need help. I have compiled the code as listed below but get the error
message:
incomparable types: boolean and char
[javac] while (continuing == '0') {
public class Results
{
private static String version =
"Module Results (version Exercise 1-4)";
static Group myGroup = new Group();
public static void main(String args[])
{
char selection;
String myNumber = "0490011";
Student thisStudent;
boolean continuing;
continuing = true;
while (continuing == '1') {
selection = IO.readChar
(version + "\n\nPlease input \n1. To display all student
results\nor\n2. To display results for Student 0490011");
switch (selection)
{
case '1':
myGroup.displayAll();
break;
case '2':
thisStudent = myGroup.findThisStudent(myNumber);
thisStudent.display();
break;
case '3':
continuing = false;
break;
default:
IO.display (version,
"You didn't select 1, 2 or 3");
}
}
System.exit(0);
}
}
It appears to me that it is a stupid error but the more I look at it the
less I see.
Help me with this one please.
Many thanks,
Donna
Carl - 08 Feb 2005 20:37 GMT
> I need help. I have compiled the code as listed below but get the error
> message:
[quoted text clipped - 52 lines]
>
> Donna
I think by (continuing == '1') you mean (continuing == true) and by
(continuing == '0') you mean to say (continuing == false).
In a while loop, you can simply write while(continuing) which will be
true as long as continuing is true.
Hth,
Carl.
Boudewijn Dijkstra - 10 Feb 2005 12:30 GMT
>I need help. I have compiled the code as listed below but get the error
> message:
> incomparable types: boolean and char
> [javac] while (continuing == '0') {
The facts:
- continuing is a boolean variable
- '0' is a char literal for the decimal number zero
- == compares two expressions and returns the result as a boolean
The problem here is, that boolean and char do not allow themselves to be
compared. In other words, continuing can never have the value '0', because it
is a boolean, not a char variable.
> public class Results
> {
[quoted text clipped - 47 lines]
>
> Donna