• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

get fooled with this programs

 
saikrishna cinux
Ranch Hand
Posts: 689
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
referring to Burkhard Hassel post
this is his program




i ran this program but unable to get the output (and also runtime exception)

if i remove lineX from this program it runs correctly..(displays the ouput)

thanks
 
Petrus Pelser
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You created an infinite loop which results that your program runs out of memory. Change the > to <.

Also remove the lineX: label as you are only allowed to label loops.
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No ..

Change i++ to i-- and change list.add(i); to list.add(new Integer(i));

int != java.lang.Integer
[ October 10, 2006: Message edited by: B L Scholtz ]
 
Burkhard Hassel
Ranch Hand
Posts: 1274
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Objection, your honor!


Saikrishna Cinux wrote:
referring to Burkhard Hassel post
this is his program]

No, you changed it a bit, see here.



And, I also posted in the original thread:
"I know, what's wrong with this code snippet. So you don't need to post it here!"

My intention was something else. Fortunately, Harshad Khasnis just wrote it (also on the original thread).



Objection 2:
Petrus Pelser wrote:
Also remove the lineX: label as you are only allowed to label loops.

This is wrong.
The following snippet compiles and runs happily:

But, admitted, these labels don't make any sense.

And, by the way, Petrus said also
Change the > to <.

Nice trap. See why?




Objection 3:
B L Scholtz wrote:
Change i++ to i-- and change list.add(i); to list.add(new Integer(i));
int != java.lang.Integer

True, but as you can see from the use of generics, the code must be java 5, not earlier. And in java 5, autoboxing would do that job.


Yours,
Bu.
 
Harshad Khasnis
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bu wrote:


Saikrishna Cinux wrote:

quote:referring to Burkhard Hassel post
this is his program]


No, you changed it a bit, see here.



And, I also posted in the original thread:
"I know, what's wrong with this code snippet. So you don't need to post it here!"

My intention was something else. Fortunately, Harshad Khasnis just wrote it (also on the original thread).




Hi Sai,
The original topic was a total different issue of discussion.
It was not a technical issue at all.
 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by saikrishna cinux:
referring to Burkhard Hassel post
this is his program




i ran this program but unable to get the output (and also runtime exception)

if i remove lineX from this program it runs correctly..(displays the ouput)

thanks


It depends on how much heap space you have as to whether it will throw an OutOfMemoryError at runtime.

Remember that the int primitive is not the same as an integer.

With a real integer, i+1 > i for all i.

But if int i = Integer.MAX_VALUE, i+1 is a negative number.
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Burkhard Hassel:

True, but as you can see from the use of generics, the code must be java 5, not earlier. And in java 5, autoboxing would do that job.


Very nice stuff. I am still from the world called Java 1.4. But at the end of this year I have the chance to do the SCJP for Java 5. There's changed a lot in the generics.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic