- 
      
- 
        Save pepet96/7743206 to your computer and use it in GitHub Desktop. 
    Sum
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | 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