Skip to content

Instantly share code, notes, and snippets.

@pepet96
Created December 2, 2013 00:56
Show Gist options
  • Save pepet96/7743206 to your computer and use it in GitHub Desktop.
Save pepet96/7743206 to your computer and use it in GitHub Desktop.
Sum
import java.util.Scanner;
class Sum {
public static void main(String [] args) {
Scanner input = new Scanner(System.in);
int n, x, absn, sum;
x = 0;
n = input.nextInt();
absn = Math.abs(n);
if (absn<10000){
if(n>=0){
while(n>0){
sum = n;
n = n - 1;
x = x + sum;
}
System.out.println(x);
}
else if(n<0){
while(n<=1){
sum = n;
n = n + 1;
x = x + sum;
}
System.out.println(x);
}
else {
System.out.println(0);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment