0

Why it happens like that?

Why it outputs second command though the numbers are the same? public class Program { public static void main(String[] args) { int a =6; int b =6; if (a<b) System.out.println("A is less than B"); else System.out.println("B is less than A"); The output is: B is less than A } }

4th Aug 2020, 8:52 AM
Umidbek
Umidbek - avatar
3 Antworten
+ 1
Thank you codemonkey
4th Aug 2020, 9:05 AM
Umidbek
Umidbek - avatar
+ 1
Thanks Tibor Santa. I understand it.
4th Aug 2020, 9:06 AM
Umidbek
Umidbek - avatar
0
You are not checking for equality. You can modify your conditions like this: if (a==b) System.out.println("A is equal to B"); else if (a<b) System.out.println("A is less than B"); else System.out.println("B is less than A");
4th Aug 2020, 9:00 AM
Tibor Santa
Tibor Santa - avatar