-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsumofvar.java
53 lines (35 loc) · 1.11 KB
/
sumofvar.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import java.util.Scanner;
public class sumofvar {
public static void sumOfDigits() {
System.out.println("This program will help you to add the digits of the number:");
double number, digit, sum = 0;
Scanner sc = new Scanner(System.in);
System.out.print("Enter the digits: ");
number = sc.nextDouble();
while(number > 0 ||number<0)
{
digit = number % 10; //seperate
sum += digit;
number = number / 10;
}
//prints the result
System.out.println("Sum of Digits: "+sum);
}
public static void addthreevar() {
double a,b,c=0;
Scanner sc=new Scanner(System.in);
System.out.println("This program will help you to add three numbers");
System.out.println("Enter the number one:");
a=sc.nextDouble();
System.out.println("Enter the number two:");
b=sc.nextDouble();
System.out.println("Enter the number three:");
c=sc.nextDouble();
double answer=a+b+c;
System.out.println("The addition of three numbers is:"+answer);
}
public static void main(String[] args) {
//clear addthreevar();
sumOfDigits();
}
}