SHOW:
|
|
- or go back to the newest paste.
1 | import java.util.*; | |
2 | - | import java.io.*; |
2 | + | import java.io.*; |
3 | ||
4 | public class Main { | |
5 | ||
6 | - | public static void main(String[] args)throws IOException { |
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; |
10 | + | |
11 | - | int i; |
11 | + | int b = 0; |
12 | - | if(a==0) { |
12 | + | |
13 | if (a == 0) { | |
14 | - | }else if(a>0) { |
14 | + | |
15 | - | b = ((1+(a))*(a))/2; |
15 | + | } else if (a > 0) { |
16 | - | }else if(a<0) { |
16 | + | b = ((1 + a) * a) / 2; |
17 | - | for (i = 1; i <= a; i--) { |
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 | } |