Skip to content

Commit df8a6ed

Browse files
authored
Update DigitalSum.java
1 parent 33baf96 commit df8a6ed

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

DigitalSum.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ class DigitalSum
66
public static void main(String args[])
77
{
88
int num,sum=0,rem;
9-
System.out.print("Enter a number: ");
9+
System.out.print("Enter a number: "); // For example, let the number be 712, expected output, 11
1010
Scanner sc=new Scanner(System.in);
11-
num=sc.nextInt();
11+
num=sc.nextInt(); // num = 712
1212
while(num>0)
1313
{
14-
rem=num%10;
15-
sum=sum+rem;
16-
num=num/10;
14+
rem=num%10; // rem = 712 % 10 = 2
15+
sum=sum+rem; // initial sum = 0, 0+2 = 2
16+
num=num/10; // num = 712 / 10 = 71, 71 greter than 0, so continue with num = 71
1717
}
1818
System.out.println("Digital Sum: "+sum);
1919
}
20-
}
20+
}

0 commit comments

Comments
 (0)