Guest User

Untitled

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