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 went wrong here? I compiled it in dr.Java and it was okay
Posted by Riyad Ahsan Auntor 17 Mar 2018 13:09
import java.util.Scanner;
public class Sum{
  public static void main(String args[]){
    Scanner sc= new Scanner(System.in);
    int N, sum=0;
    System.out.print("Enter the value of N:");
    N= sc.nextInt();
    if(N<10000){
      if(N<0){
        for(int x=N; x<=1; x++){
          sum+=x;
        }
      }
        else{
          for(int x=1; x<=N; x++){
            sum+=x;
          }
        }
    }
    System.out.println(sum);
  }
}
Re: what went wrong here? I compiled it in dr.Java and it was okay
Posted by Oleg Baskakov 17 Mar 2018 16:29
System.out.print("Enter the value of N:");
comment this out, automatic checker doesn't know that this text isn't the part of your answer
Re: what went wrong here? I compiled it in dr.Java and it was okay
Posted by Riyad Ahsan Auntor 19 Mar 2018 21:32
yup did that too and it still says wrong answer
Re: what went wrong here? I compiled it in dr.Java and it was okay
Posted by Oleg Baskakov 20 Mar 2018 04:51
Okaaaaay...

if(N<10000){
i assume you wanted to check here if input data is correct, but there's no need to do that, input data is correct by default.
Not to mention that you do it wrong, you check if N is between (-infinity; 9999], while N should be between [-10000; 10000].

Also i think you don't handle the N=0 case correctly, but hopefully you'll figure out why without more hints.