lab-03:
- Parse ints class. - Still no Ex handling
This commit is contained in:
parent
4b8ebcf60c
commit
810480828a
18
lab-03/src/ParseInts.java
Normal file
18
lab-03/src/ParseInts.java
Normal file
@ -0,0 +1,18 @@
|
||||
import java.io.PrintStream;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class ParseInts {
|
||||
public static void main(String args[]){
|
||||
Scanner in = new Scanner(System.in);
|
||||
PrintStream out = System.out;
|
||||
out.println("Enter a line of text: ");
|
||||
String line;
|
||||
Scanner scanLine = new Scanner(in.nextLine());
|
||||
int sum = 0;
|
||||
while (scanLine.hasNext()){
|
||||
int val = Integer.parseInt(scanLine.next());
|
||||
sum += val;
|
||||
}
|
||||
out.println("The sum of the integers on this line is " + sum);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user