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

Can you please tell me what's am wrong?
Posted by Axeus 21 Mar 2011 16:04
import java.util.Scanner;

public class Sum {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int num = sc.nextInt();
        if(num < 0){
            num = Math.abs(num);
            num = ((num*(num+1)/2)-1)*-1;
            System.out.println(num);
        }else if(num > 0 && num < 10000){
            num = num*(num+1)/2;
            System.out.println(num);
        }else if(num == 0){
            num = 1;
            System.out.println(num);
        }
        System.out.flush();
    }
}
Re: Can you please tell me what's am wrong?
Posted by Manikandan 29 Mar 2011 18:10
Do not use scanner classes. I got WA for a program. Use the bufferedreader and then parse it.