From f5e1d7307bafec3417b4537f83417f2e00ec98dc Mon Sep 17 00:00:00 2001 From: mohithsm <132048478+mohithsm@users.noreply.github.com> Date: Thu, 4 May 2023 13:00:01 +0530 Subject: [PATCH] Create mohith.java --- mohith.java | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 mohith.java 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); +} +}