Can anyone help me to understand output of this code? Only true mathematician and programmer can only solve it.
22 Answers
New AnswerI am unable to understand output of this code.Help me! https://code.sololearn.com/c1vNQf3oatKA/?ref=app Only true mathematician and programmer can only solve it.
12/1/2020 2:02:13 PM
Vikash Godara22 Answers
New AnswerIt will give some garbage value... Check this how u get out of range.. Run this 👇 https://code.sololearn.com/cdDvrjOaKTR2/?ref=app
Vikash Godara My app crashed when i run ur infinite loop ...Lol It have ended bcos of "Execution Timed out"...
Vikash Godara It simply means ur Programming is running out of time..Any program must complete execution within a certain amount of time...if it exceeds it , the program terminates...
It will run forever on your own machine. The numbers will eventually overflow and go negative if left long enough. The code playground terminates programs after a certain amount of time to prevent errant or malicious code from consuming the servers resources. Edit: Not quite forever. If you increment pt often enough it will overflow and become negative at which point the loop will terminate. try editing the code to read... for (pt =Integer.MAX_VALUE-2; pt > 0;pt++){ pt will increment twice to reach MAX_VALUE after the third time it will overflow and become negative so it will only print 3 values. You will also notice that the values alternate between positive and negative as the calculations overflow the integer range
@Coding Kitty, who's profile are you looking at? I'm only seeing 18 xp for Java on Vikash Godara's profile, or are you looking at his total xp?
Alphin K Sajan But why computer stopped giving output. It's will be never ending but it's have ending.
This loop is infinite as the value of pt is increasing therefore always greater than 0 so the output will run until the timeout for the compiler in my case.
You're running an infinite loop. What is "Only true mathematician and programmer can only solve it." doing here huh?
So basically the output is simple it just adds the vale of one to the next num that of the last number.
pt will increase by 1 (It will not increase in the first time of the execution of the loop). n will increase by pt. As pt is always greater than 0, so it will continue and will give - 2 4 7 11 16 (And so on.........................) This is a good example of an infinite loop.
Learn Playing. Play Learning
SoloLearn Inc.
4 Embarcadero Center, Suite 1455Send us a message