# Field Manual for Hackers

## java - Write a program to find the sum of digit of a given number.

1. import java.util.Scanner;
class Sum
{
public static void main(String Args[])
{
System.out.println("enter the integer");
int num;
Scanner sc=new Scanner(System.in);
num=sc.nextInt();
int sum=0;
while(num!=0)
{
sum=sum+num%10;
num=num/10;
}
System.out.println("sum is"+sum);
}
}

2. import java.util.Scanner;
class DigitSum
{
public static void main(String ar[])
{int Number,Total=0;
Scanner scan=new Scanner(System.in);
System.out.println("Enter thee Digit");
Number=scan.nextInt();
while(Number>0)
{
Total=Total+(Number%10);
Number=Number/10;
}
System.out.println("Sum is="+Total);
}
}

3. import java.util.Scanner;

class Test{

public static void main(String ar[])
{

Scanner sc=new Scanner(System.in);
int num,sum=0;
System.out.println("Enter Number to find sum of digits");
num=sc.nextInt();
while (num > 0)
{
sum+=num%10;
num/=10;
}
System.out.println("Sum of digits is = "+sum);

}
}

4. import java.util.Scanner;

class Test
{

public static void main(String ar[])
{
double number;
int number1,sum=0;
System.out.print("Enter the number: ");
Scanner o= new Scanner(System.in);
number=o.nextDouble();
number1=(int)number;
while(number1!=0)
{
sum=sum+(number1%10);
number1=number1/10;
}

System.out.println("The sum of individual digits is: "+sum);

}
}

5. \$num1=\$_POST["num"];
\$temp=\$num1;
\$sum=0;
while(\$temp>=1)
{
\$sum+=\$temp%10;
\$temp/=10;
}
echo "Sum of digits of \$num1= \$sum
";

6. import java.util.Scanner;
class sumofdigits
{
public static void main(String ar[])
{
Scanner scan = new Scanner(System.in);
int sum = 0 , remainder , number;
System.out.println("Enter the number");
number = scan.nextInt();
while(number!=0)
{
remainder = number % 10;
sum = sum + remainder;
number /= 10;
}
System.out.println("the sum of digits is : " +sum);

}
}

7. import java.util.Scanner;
class Fact{
public static void main(String ar[]){
Scanner obj=new Scanner(System.in);
int num,rem,sum=0;
System.out.println("enter the value of number");
num=obj.nextInt();
while(num!=0){
rem=num%10;
num=num/10;
sum=sum+rem;
}
System.out.println("sum is"+sum);
}
}

8. import java.util.Scanner;

class Sum{
public static void main(String ar[]){
int number,temp=0;

Scanner scan=new Scanner(System.in);
System.out.println("Enter the number:");
number=scan.nextInt();

while(number>0){
temp=temp+(number%10);
number=number/10;
}
System.out.println("The sum of the digits is:"+temp);
}
}

9. This comment has been removed by the author.

10. import java.util.*;
class Sum{
public static void main(String ar[]){
Scanner s= new Scanner(System.in);
int n,sum=0;
System.out.println("enter the number");
n=s.nextInt();
while(n!=0)
{
sum+=(n%10);
n=n/10;
}
System.out.println("the sum of digits is : " +sum);
}
}

11. import java.util.Scanner;

class SumDigit{

public static void main(String ar[]){

Scanner scan=new Scanner(System.in);
int num,sum=0,rem;
System.out.println("Enter number");
num=scan.nextInt();
while(num!=0){
rem=num%10;
sum=sum+rem;
num=num/10;

}
System.out.println("sum="+sum);

}

}

12. import java.util.Scanner;
public class Sum {
public static void main(String[]ar){
System.out.println("Enter the integer");
int Num;
Scanner s=new Scanner(System.in);
Num=s.nextInt();
int Sum=0;
while(Num!=0){
Sum=Sum +Num%10;
Num=Num/10;
}System.out.println("Sum: \n"+Sum);
}
}