Computer Science, asked by rishitarajmishra, 1 month ago

Write a program to print sum of digits of a given number using a method, int sumDigits(int num)​

Answers

Answered by saisankalap130
1

Answer:

import java.util.Scanner;

public class Digit_Sum

{

public static void main(String args[])

{

int m, n, sum = 0;

Scanner s = new Scanner(System.in);

System.out.print("Enter the number:");

m = s.nextInt();

while(m > 0)

{

n = m % 10;

sum = sum + n;

m = m / 10;

}

System.out.println("Sum of Digits:"+sum);

}

}

Answered by gitanjaligitajlai498
1

Answer:

yrrr nhi janti

pr kyaa huaa hai ?aap ye btaoo sis plz

Attachments:
Similar questions