write a program to accept any number through command line and find sum of digit of that number in java..
Answers
Answered by
8
Answer:
import java.util.Scanner;
public class CommandLineInput
{
public static void main(int n)
{
int s=0;
for(;n>0;n/=10){
s+=n%10;
}
System.out.println("Sum of digits="+s);
}
}
------
Variable Description:-
- s:- to calculate sum
- n:- to accept number through command line input
------
Output Attached
Explanation:
Attachments:
Similar questions
Chemistry,
1 month ago
Physics,
1 month ago
Computer Science,
4 months ago
Physics,
10 months ago
Art,
10 months ago