-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDebugSeven2.java
More file actions
39 lines (39 loc) · 1.16 KB
/
DebugSeven2.java
File metadata and controls
39 lines (39 loc) · 1.16 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
// Program prompts user to enter a series of integers
// separated by spaces
// Program converts them to numbers and sums them
import java.util.*;
public class DebugSeven2
{
public static void main(String[] args)
{
String str;
int x;
int length;
int start = 0;
int num;
int lastSpace = -1;
int sum = 0;
String partStr;
Scanner in = new Scanner(System.in);
System.out.print("Enter a series of integers separated by spaces >> ");
str = in.nextLine();
length = length();
for(x = 0; x <= length; ++x)
{
if(str.charAt(x) == " ")
{
partStr = str.substring(x, lastSpace + 1);
num = Integer.parseInt(partStr);
System.out.println(" " + num);
sum = num;
lastSpace == x;
}
}
partStr = str.substring(lastSpace + 1, length);
num = Integer.parseInt(partStr);
System.out.println(" " + num);
sum = num;
System.out.println(" -------------------" +
"\nThe sum of the integers is " + sum);
}
}