
Control Loops 3.25
3. public static void main(String[] args) {
4. int num = 989989,rem,sum=0, count =0,temp;
5. temp=num; // store it in temp
6. do
7. {rem=num%10; // finds remainder
8. num=num/10;
9. count++;//increments counter
10. sum+=rem; //adds remainder to sum
11. }while( num>0);
12. System.out.println(“Given Number” + temp);
13. System.out.println(“No of digits=” + count);
14. System.out.println(“Sum of digits=” +sum);
15. }
16. }//end of class
Output: Given Number989989 No of digits=6 Sum of digits=52
3.13.3 For Loop
For loop, as control loop is used, when we know the exact number of times the loop needs to
be executed. The ...