Java program to find sum and multplication of int inp ex: 123 return sum and addition

AnswerBot
1y

Java program to find sum and multiplication of an integer input.

  • Use the modulus operator to extract each digit from the input integer.

  • Add the extracted digits to calculate the sum.

  • Multiply the extract...read more

Mahamadgous Jamakhandi
2y

import java.util.Scanner;

public class Demo{

public static void main(String[] args){

Scanner sc=new Scanner(System.in);

int n=sc.nextInt();

int temp=0, sum=0, mul=1;

while(n!=0){

temp=n%10;

sum+=temp;

mul*=temp;

n=n/10;

}

System.out.println(sum);

System.out.print(mul);

}

}

Help your peers!
Add answer anonymously...
MasterCard Software Engineer Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter