Advertisement
Guest User

Untitled

a guest
Dec 3rd, 2014
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  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. int b=0;
  11. int i;
  12. if(a==0) {
  13. b = 1;
  14. }else if(a>0) {
  15. b = ((1+(a))*(a))/2;
  16. }else if(a<0) {
  17. for (i = 1; i <= a; i--) {
  18. b += i;
  19. }
  20. }
  21. PrintWriter pw = new PrintWriter(new File("output.txt"));
  22. pw.print(b);
  23. pw.close();
  24.  
  25. }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement