How the while loop running in this program?

Report
Question

Please briefly explain why you feel this question should be reported .

Report
Cancel

How this while loop running in this program.How the two digits added in this program.Please explain this to me.I am eagerly waiting for this.

  1. import java.util.Scanner;
  2. public class Exercise6 {
  3.   public static void main(String[] args)
  4.     {
  5.       Scanner in = new Scanner(System.in);
  6.       System.out.print(“Input an integer: “);
  7.       int digits = in.nextInt();
  8.       System.out.println(“The sum is “ + sumDigits(digits));
  9.     }
  10.  public static int sumDigits(long n) {
  11.         int result = 0;
  12.         while(n > 0) {
  13.             result += n % 10;
  14.             n /= 10;
  15.         }
  16.         return result;
  17.     }
  18.  }
in progress 0
Java 6 months 1 Answer 435 views 1

Answer ( 1 )

  1. rg123

    Please briefly explain why you feel this answer should be reported .

    Report
    Cancel

    See the flowchart (attachment):


    Attachment

Leave an answer

Browse

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>