Codeforces celebrates 10 years! We are pleased to announce the crowdfunding-campaign. Congratulate us by the link https://codeforces.com/10years. ×

islam_hmam's blog

By islam_hmam, history, 15 months ago, In English,

this code give me run time error i dont know why ,This program for get sum of any number digits by java

https://ideone.com/e.js/WboQW1

i try it in netbeans and dont give any wrong

https://codeforces.com/group/bb2AzpRPk4/contest/233552/problem/H

 
 
 
 
  • Vote: I like it
  • -14
  • Vote: I do not like it

»
15 months ago, # |
  Vote: I like it 0 Vote: I do not like it

I'm not sure why that would cause a run time error, but the definition of run time error is an error that occurs while the program is running. (versus compile time error which is an error that happens while the program is being compiled, before it is run).

There's many reasons for run time errors such as accessing array out of bounds or overflows. I know that in c++ it is definitely compiler dependent, dunno for Java. An example of a compile time error is trying to instantiate an abstract class.

That's what I can tell you, but none of this may be correct (just my understanding) so take it with a grain of salt.

»
15 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Runtime error means that in the middle of the execution something went wrong and the program had to stop.

Probably you have problem with line 17. If you are using Scanner, you could use directly in.NextInt() instead of reading a string and parse it.

  • »
    »
    15 months ago, # ^ |
    Rev. 2   Vote: I like it 0 Vote: I do not like it

    haha, I didn't even realize you could scroll, I assumed it was an image. But I have a question, what's the difference between reading in a string then converting it and just reading in an int? (I see both as ok, run time error-wise.) Just trying to understand why exactly it would cause a run time error. I'm curious, what did the user put for the input?

  • »
    »
    15 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    The both are same so i dont know why it cause run time error ,But thanks about your advice and i will try it

    • »
      »
      »
      15 months ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      What input did you put that's giving you the run time error??

      • »
        »
        »
        »
        15 months ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        Test one

        123

      • »
        »
        »
        »
        15 months ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        It gives me right answer in netbeans ide 6

        But in codeforcesse it gives me run time error

        • »
          »
          »
          »
          »
          15 months ago, # ^ |
            Vote: I like it 0 Vote: I do not like it

          For some reason, it's not letting me access the link you posted. I am getting 6 as well. But I only copied your main. Can you give me another link to the problem?

          • »
            »
            »
            »
            »
            »
            15 months ago, # ^ |
              Vote: I like it 0 Vote: I do not like it

            Ooh ops

            Its not allawed because it is a private contest in private group

»
15 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by islam_hmam (previous revision, new revision, compare).

»
15 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by islam_hmam (previous revision, new revision, compare).

»
15 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by islam_hmam (previous revision, new revision, compare).

»
15 months ago, # |
  Vote: I like it 0 Vote: I do not like it

If the error happens on the first test, it may be because the problem requires reading from file, and you try to read from the standard input. It's empty, hence in.next() fails. It happens while program is running, hence the name "run-time error".

»
4 weeks ago, # |
  Vote: I like it -13 Vote: I do not like it

Could anyone help me please, I also get Runtime error on the following code. But Would not it need to be TLE instead of Runtime?

In C++ Solution, I wrote the following while 0 <= n <= 10^9;

vector vec(n, 0);

I know this is wrong anyway but Why this gives runtime error instead of Time Limit Exceeded?

  • »
    »
    4 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    How does this give TLE just by writing vector vec(n,0). TLE happens when you do more operations than the maximum operations that you can do in a time limit.

    • »
      »
      »
      2 weeks ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Now, I see, it is because memory. I am trying to take more memory than the question gives. That's way it gives runtime error. Sorry for asking this stupid question.

»
4 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

Nice spam to recent actions.