Write a Java Program to find the Sum Of Digits Of Number
Basic Java programs. All programs done in very simple ways. It helps beginners to grow their programming skills and build a programming logic.
Write a Java Program to find the Sum Of Digits Of Number
import java.util.Scanner; public class SumOfDigitsOfNumber { public static void main(String[] args) { Scanner scan = new java.util.Scanner(System.in); System.out.println("Enter the N: "); int N=scan.nextInt(); int reminder,sum=0; while(N>0) { reminder=N%10; sum=sum+reminder; N=N/10; } System.out.println("Sum of Digits: "+sum); } }Output:
No comments:
Post a Comment
If you have any doubts, please let me know