Computer Science, asked by pramukh0504, 1 year ago

Write a java program to accept 3 digit number and find sum of its digits by using scanner

Answers

Answered by softwarecrackerindia
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