Advertisement
Guest User

Untitled

a guest
Dec 3rd, 2014
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.*;
  2. import java.io.*;
  3.  
  4. public class Main {
  5.  
  6. public static void main(String[] args) throws IOException {
  7. Scanner sc = new Scanner(new File("input.txt"));
  8. int a = sc.nextInt();
  9. sc.close();
  10.  
  11. int b = 0;
  12.  
  13. if (a == 0) {
  14. b = 1;
  15. } else if (a > 0) {
  16. b = ((1 + a) * a) / 2;
  17. } else if (a < 0) {
  18. for (int i = 1; i <= a; i--) {
  19. b += i;
  20. }
  21. }
  22.  
  23. PrintWriter pw = new PrintWriter(new File("output.txt"));
  24. pw.print(b);
  25. pw.close();
  26. }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement