0
Can anyone explain this code please :)
public class Program { public static void main(String[] args) { int num=4162; int temp=0; while(num>0) { temp = temp +num%10; num /= 10; } System.out.println(temp); } } Output:13
1 Odpowiedź
+ 3
temp=0+2
num=416
temp=2+6
num=41
temp=8+1
num=4
temp=9+4
num=0
while loop breaks since num is not greater than 0
and 13 gets printed
in num%10 ,operator "%" returns remainder