Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The program is given which takes the number from the user.Just complete the foll

ID: 3564989 • Letter: T

Question

The program is given which takes the number from the user.Just complete the following empty method
named addDigits returning an int which will take integer as a parameter
which is a number given by the user. then it will return the sum of its digit.
For example if user enters 132 then function should return 1+2+3=6
If input is 120 then it should return 1+2+0=3

/*Lucky number calculater(just calculates the sum of digits of the given date*/
import java.io.*;
class digitsum{

public static void main(String arg[])throws Exception{

BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the date(ddmmyy):");
int number =Integer.parseInt(br.readLine());

int sum=addDigits(number);
System.out.println("sum of digits is:");
System.out.println(sum);   
}

//main

static int addDigits(int number){

//write your code here
//start

//end
///}

}

}

Explanation / Answer

/*Lucky number calculater(just calculates the sum of digits of the given date*/
import java.io.*;
class digitsum{

public static void main(String arg[])throws Exception{

BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the date(ddmmyy):");
int number =Integer.parseInt(br.readLine());

int sum=addDigits(number);
System.out.println("sum of digits is:");
System.out.println(sum);   
}

//main

static int addDigits(int number){

int sum = 0;
  
   while(number > 0){
   sum = sum + number%10;
       number = number/10;
   }
  
   return sum;

//write your code here
//start

//end
///}

}

}