Advertisement
Guest User

Untitled

a guest
Dec 9th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. package zad1;
  2. import java.io.*;
  3. import java.util.*;
  4.  
  5. public class Main {
  6.  
  7. public static void main(String[] args) {
  8. String fname = System.getProperty("user.home") + "/iter.txt";
  9. File f = new File(fname);
  10. int sum = 0;
  11. int start = 0;
  12. int end = 0;
  13. int limit = 0;
  14. try {
  15. Scanner scan = new Scanner(f);
  16. start = scan.nextInt();
  17. end = scan.nextInt();
  18. limit = scan.nextInt();
  19. for (int i = start; i <= end; i++) {
  20. sum += i;
  21. if (sum >= limit) break;
  22. }
  23. if (sum <= limit) {
  24. System.out.println(sum);}
  25. else {System.out.println(limit);}
  26. } catch (Exception exc) {
  27. System.out.println("***");
  28. }
  29. }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement