From 810480828a16b63f63ae88a0bdc53e94a6c43484 Mon Sep 17 00:00:00 2001 From: HeshamTB Date: Fri, 2 Oct 2020 16:24:58 +0300 Subject: [PATCH] lab-03: - Parse ints class. - Still no Ex handling --- lab-03/src/ParseInts.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 lab-03/src/ParseInts.java diff --git a/lab-03/src/ParseInts.java b/lab-03/src/ParseInts.java new file mode 100644 index 0000000..37f2f70 --- /dev/null +++ b/lab-03/src/ParseInts.java @@ -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); + } +}