ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1068. Sum

wa9.
Posted by Andrew 27 Nov 2016 17:21
import java.util.*;
public class JavaApp {

    public static void main(String[] args) {
             int i=0;

                Scanner scan = new Scanner(System.in);
        int n=scan.nextInt();

                if ((n>=1)&&(n<10000)){
                    i=n *(n + 1) / 2;
                    System.out.print(i);}
                else
                if ((n<=1)&&(n>-10000)){
                    i=-((-n) *(1 -n) / 2) + 1;
                    System.out.print(i);}
        };
    }
Re: wa9.
Posted by Andrew 6 Feb 2017 17:28
import java.util.Scanner;

public class tests {


    public static void main(String[] args) {
             int i=0;

                Scanner scan = new Scanner(System.in);
                try{
                int n=scan.nextInt();
                if ((n>=1)&&(n<=10000)){
                    i=n *(n + 1) / 2;
                    System.out.print(i);}
                else
                if ((n<=1)&&(n>=-10000)){
                    i=-((-n) *(1 -n) / 2) + 1;
                    System.out.print(i);}
                }
                finally
                {
                    scan.close();
                    }
        }
}