In this article we will learn about some of the frequently asked TypeScript programming questions in technical like “Java program to find the sum of all the digits in the inputted number” Code Answer’s. When creating scripts and web applications, error handling is an important part. If your code lacks error checking code, your program may look very unprofessional and you may be open to security risks. Error or stack handling on typescript was simple and easy. An error message with filename, line number and a message describing the error is sent to the browser. This tutorial contains some of the most common error checking methods in Typescript. Below are some solution about “Java program to find the sum of all the digits in the inputted number” Code Answer’s.
Java program to find the sum of all the digits in the inputted number
xxxxxxxxxx
long number, sum;
Scanner sc = new Scanner(System.in);
System.out.println("Enter any DIGIT number: ");
number = sc.nextLong();
sc.close();
// For Logic for adding all digits in the given number
for (sum = 0; number != 0; number /= 10) {
sum += number % 10;
}
System.out.println("ForLoop Sum of ALL digits: " + sum);
JAVA Program than read an integer and calculate the sum of its digits and write the number of each digit of the sum in English
xxxxxxxxxx
import java.util.*;
public class Main
{
public static void main(String[] args)
{
int m, n, sum = 0;
Scanner sc=new Scanner(System.in);
System.out.print("Enter the number:");
m = sc.nextInt();
while(m > 0)
{
n = m % 10;
sum = sum + n;
m = m / 10;
}
System.out.println("Sum of Digits:"+sum);
int v,a,r=0;
String[] number = {"zero","one","two","three","four","five","six","seven","eight","nine"};
while(sum!=0)
{
a=sum%10;
r=r*10+a;
sum=sum/10;
}
System.out.print("In Inglish : ");
while(r!=0)
{
v=r%10;
System.out.print(number[v]+" ");
r=r/10;
}
}
}
sum of digits in java
xxxxxxxxxx
import java.io.*;
public class sd
{
public static void main(String [] args)throws IOException
{
InputStreamReader hi = new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(hi);
System.out.println("Enter the number");
int num=Integer.parseInt(in.readLine());
int sum=0;
while(num>=0)
{
int rem=n;
sum+=rem;
int quo=n/10;
n=quo;
}
System.out.println(sum);
}
}