Here is the code that can help you to get the total sum as well as multiplication values of all the digits in the given number.
- import java.io.*;
- class Sum
- {
- int total=0,remainder;
- public void add(int num)
- {
- while(num>0)
- {
- remainder = num % 10;
- total = total + remainder;
- num = num / 10;
- }
- System.out.println("Sum of the digits in the given number is:"+total);
- }
- }
- class Summation
- {
- public static void main(String args[])throws IOException
- {
- int num;
- Sum s=new Sum();
- BufferedReader br= new BufferedReader(new InputStreamReader(System.in));
- System.out.println("\nEnter the number:");
- num=Integer.parseInt(br.readLine());
- s.add(num);
- }
- }
Thank you, keep learning and sharing.