+ 1

Why it is showing 0 in second time?

public class Program { public static void main(String[] args) { int n=94; int sum=0; int i=2; while(n>0) { sum+=n%10; n/=10; } System.out.println (sum); sum=0; while(n>1) { if(n%i==0) { sum+=i; } else i++; } System.out.println (sum); } }

23rd May 2022, 2:28 PM
Atul
1 Respuesta
+ 4
"n" is 0 after the first while loop
23rd May 2022, 2:31 PM
Lisa
Lisa - avatar