Computer Science, asked by BrainlyPromoter, 10 months ago

Write a java program to input any number and find the sum of the digits using while loop.

Answers

Answered by TheDeViLB
15
\Huge{\mathfrak{\red{Answer;}}}


import java .util.*;

class abc

{


public static void main(String args[])

{

Scanner sc = new Scanner (System.in);


System.out.println("Enter a no=");

int n= sc.nextInt();

int temp =n;
int sum= 0;

while(n>0)

{

int r = n%10;

sum= sum+ r;

n=n/10;

}
System.out.println("Sum="+sum );


}

}

Answered by muakanshakya
12
\Huge{\mathfrak{\underline{AnSwEr;}}}



import java .util.Sacnner ;

or


import java.util.*;

class sum

{


public static void main(String args[])

{

Scanner sc = new Scanner (System.in);


System.out.println("Enter a no=");

int n= sc.nextInt();

int temp =n;
int sum= 0;

while(n>0)

{

int d = n%10;

sum= sum+ d;

n=n/10;

}

System.out.println("Sum of the digits ="+sum );


}

}




Similar questions