Write a java program to accept 3 digit number and find sum of its digits by using scanner
Answers
Answered by
6
class SumOfDigits { public static void main(String args[]) { int n; int a=0; int sum=0; //taking integer number from command line and parsing the same n=Integer.parseInt(args[0]); while(n!=0) { a=n%10; n=n/10; sum=sum+a; } System.out.println("Sum of digits: " + sum); } }
pramukh0504:
You didn't use Scanner
Similar questions
Computer Science,
7 months ago
Computer Science,
7 months ago
Computer Science,
7 months ago
Math,
1 year ago
Math,
1 year ago
Chemistry,
1 year ago