Can anyone help me to understand output of this code? Only true mathematician and programmer can only solve it. | SoloLearn: Learn to code for FREE!

0

Can anyone help me to understand output of this code? Only true mathematician and programmer can only solve it.

I 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 Godara

22 Answers

New Answer

+11

Vikash Godara Bro u have written an infinite for Loop...Lol

+11

Ah how cute! The newbie with 18 xp in Java has written an infinite loop.

+5

It will give some garbage value... Check this how u get out of range.. Run this 👇 https://code.sololearn.com/cdDvrjOaKTR2/?ref=app

+5

Vikash Godara My app crashed when i run ur infinite loop ...Lol It have ended bcos of "Execution Timed out"...

+5

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...

+5

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

+4

Vikash Godara Wlcm :)

+3

@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?

+2

Alphin K Sajan But why computer stopped giving output. It's will be never ending but it's have ending.

+2

Alphin K Sajan What is mean of Execution Timed out.Is time ends of computer?

+2

Alphin K Sajan Thanks!

+2

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.

+2

Martin Taylor well. currently he has 164xp

+2

You're running an infinite loop. What is "Only true mathematician and programmer can only solve it." doing here huh?

+1

Alphin K Sajan But why answer is in minus(-).Answer will be never printed

+1

Martin Taylor It's because I already know java,python,html and css.

+1

0

So basically the output is simple it just adds the vale of one to the next num that of the last number.

0

Brother,you write for loop,for execute infinite number of times,it never stops.

0

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.