Computer Science, asked by aansimendpara299, 1 month ago

write a program to accept any number through command line and find sum of digit of that number in java..​

Answers

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