|
|
back to boardDiscussion of Problem 1068. Sumwhat went wrong here? I compiled it in dr.Java and it was okay 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 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 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 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. |
|
|