Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.io.*;
- public class Main {
- public static void main(String[] args)throws IOException {
- Scanner sc = new Scanner(new File("input.txt"));
- int a = sc.nextInt();
- sc.close();
- int b=0;
- int i;
- if(a==0) {
- b = 1;
- }else if(a>0) {
- b = ((1+(a))*(a))/2;
- }else if(a<0) {
- for (i = 1; i <= a; i--) {
- b += i;
- }
- }
- PrintWriter pw = new PrintWriter(new File("output.txt"));
- pw.print(b);
- pw.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement