Ternary.java


#1

public class Ternary {
public static void main(String[] args) {

    int fuelLevel =0;

  char canDrive =
  (fuelLevel>0)? 'Y': 'N';
    System.out.println(canDrive);

}

}
what am I doing wrong ? It does in fact run on the console but i get an error message stating have I set .Set the canDrive variable equal to the ternary expression: (fuelLevel > 0) ? 'Y' : 'N';
please give me some idea.. thanks


#2

Not able to reproduce this error, even using your exact code. Perhaps refresh the page and try again.


#3

I haven't tested this, but maybe try to get all the spaces exactly like the error is asking for.


#4

That's the issue. I used the exact code, spacing and all, with no error. Puzzling...


#5

Yes, I agree .......


#6

Did you try setting fuelLevel equal to something greater than 0? Maybe that's the issue?


#7

public class Ternary {
public static void main(String[] args) {

	int fuelLevel = 3;

char canDrive = (fuellevel > 0) ? 'Y' : 'N';
System.Out.Println(canDrive);

}

}
I am getting error for an infinite loop
Please suggest what is wrong


#8

public class Ternary {
public static void main(String[] args) {

int fuelLevel = 3;

char canDrive = (fuellevel > 0) ? 'Y' : 'N';
System.Out.Println(canDrive);

}
}
I am getting error for an infinite loop
Please suggest what is wrong


#9

Infinite loop? I don't think so.

Here:

(fuellevel > 0) ? 'Y' : 'N';

variable fuellevel is not defined, it must be fuelLevel.


Java is case sensitive, find next problems without our help.


#10


#11

Java is case sensitive. Just try to find this without our help. There are two problems in the line number 6.


#12

i found out .. I am new to this case sensitiveness .. Anyways thanks a lot .


#13

Add spaces after every word in the ternary operator..
like this canDrive = (fuelLevel>0) ? 'Y' : 'N' ;
Hope this will work...


#14

That works, thank you!


#16

A post was split to a new topic: unable to move ahead in this exercise


#17

A post was split to a new topic: I don't know what I'm doing wrong


#18