Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 1 // Program that reads five numbers and reports their sum.
- 2
- 3 import java.io.*;
- 4 import java.util.*;
- 5
- 6 public class ShowSum1 {
- 7 public static void main(String[] args)
- 8 throws FileNotFoundException {
- 9 Scanner input = new Scanner(new File("numbers.dat"));
- 10
- 11 double sum = 0.0;
- 12 for (int i = 1; i <= 5; i++) {
- 13 double next = input.nextDouble();
- 14 System.out.println("number " + i + " = " + next);
- 15 sum += next;
- 16 }
- 17 System.out.println("Sum = " + sum);
- 18 }
- 19 }
Add Comment
Please, Sign In to add comment