-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExercise02_06.java
More file actions
42 lines (38 loc) · 1.21 KB
/
Exercise02_06.java
File metadata and controls
42 lines (38 loc) · 1.21 KB
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
package Chapter2;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
import java.util.Scanner;
/**
*
* @author jorda
*/
public class Exercise02_06 {
public static void main(String[] args){
String nString;
char char1, char2, char3, char4;
int int1, int2, int3, int4, sumOfInts;
Scanner input = new Scanner(System.in);
System.out.print("Please enter a three digit integer:");
nString = input.next();
char1 = nString.charAt(0);
char2 = nString.charAt(1);
char3 = nString.charAt(2);
//char4 = nString.charAt(3);
int1 = Character.getNumericValue(char1);
int2 = Character.getNumericValue(char2);
int3 = Character.getNumericValue(char3);
//int4 = Character.getNumericValue(char4);
sumOfInts = int1 + int2 + int3; // + int4;
System.out.println("The sum of all digits is: " + sumOfInts);
//uncomment to debug
/*
System.out.println(int1);
System.out.println(int2);
System.out.println(int3);
System.out.println(int4);
*/
}
}