diff --git a/mohith.java b/mohith.java new file mode 100644 index 0000000..bfb0075 --- /dev/null +++ b/mohith.java @@ -0,0 +1,22 @@ +import java.util.Scanner; +public class SumOfDigitsExample1 +{ +public static void main(String args[]) +{ +int number, digit, sum = 0; +Scanner sc = new Scanner(System.in); +System.out.print("Enter the number: "); +number = sc.nextInt(); +while(number > 0) +{ +//finds the last digit of the given number +digit = number % 10; +//adds last digit to the variable sum +sum = sum + digit; +//removes the last digit from the number +number = number / 10; +} +//prints the result +System.out.println("Sum of Digits: "+sum); +} +}