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

What Wrong?
Posted by WEE YING KIT 5 Jun 2015 15:13

import java.util.Scanner;
import java.io.*;

public class HelloWorld {

    public static void main(String args[]) {

        int a = 0;
        int total = 0;
        Scanner input = new Scanner(System.in);
        a = input.nextInt();


            total = convertFunc(a);
            System.out.println(total);
    }

        public static int convertFunc(int n){

        int sum = 0;
        if(n > 0 && n <= 10000 )
        {
            for(int i = 1 ; i <= n ; i++ )
            {
                sum += i;
            }
        }
        else
        {
            for(int i = 1 ; i >= n ; i--)
            {
                sum += i;
            }
        }
        return sum;
    }
}