class A{
public static void main (String [] args ){
int x=4;
x=x==4?x/2:x%2;
System.out.println (x);
}
}
Czy może mi ktoś wytłumaczyć jak program oblicza to równanie?
class A{
public static void main (String [] args ){
int x=4;
x=x==4?x/2:x%2;
System.out.println (x);
}
}
Czy może mi ktoś wytłumaczyć jak program oblicza to równanie?
Najpierw poprawmy formatowanie:
x = (x == 4) ? (x / 2) : (x % 2);
Teraz: ?
to ternary operator
- tłumaczy się go tak:
if (x == 4) {
x = x / 2;
} else {
x = x % 2;
}