Skip to content
Snippets Groups Projects
Commit ed02b45a authored by Brady James Garvin's avatar Brady James Garvin
Browse files

Modified summation for demonstrations of try/catch and refactoring for reuse.

parent 2e328679
No related branches found
No related tags found
No related merge requests found
......@@ -3,14 +3,18 @@ package edu.unl.cse.soft160.sum;
import java.util.Scanner;
public class Sum {
public static void main(String[] args) {
Scanner firstScanner = new Scanner(args[0]);
double firstNumber = firstScanner.nextDouble();
firstScanner.close();
Scanner secondScanner = new Scanner(args[1]);
double secondNumber = secondScanner.nextDouble();
secondScanner.close();
double sum = firstNumber + secondNumber;
System.out.println("The sum is " + sum + ".");
public static void main(String... arguments) {
double augend = 0, firstAddend = 0, secondAddend = 0;
Scanner scanner = new Scanner(System.in);
System.out.print("Enter the augend: ");
augend = scanner.nextDouble();
System.out.print("Enter the first addend: ");
firstAddend = scanner.nextDouble();
System.out.print("Enter the second addend: ");
secondAddend = scanner.nextDouble();
scanner.close();
String message = augend + " + " + firstAddend + " + " + secondAddend + " = "
+ (augend + firstAddend + secondAddend);
System.out.println(message);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment