float x=2.3;
if(x>2.2) {
System.out.println("X is greater than 2.3");
}
What is the output of this program in Java..
Ans: Compilation fails.
Solution: 'x' is a float variable. and '2.2' gets converted to 'double'. we cannot compare a float and a double. We need to mention it as 'x>2.2f' for the above code to print the output.
0 comments:
Post a Comment