By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,778 Members | 1,074 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,778 IT Pros & Developers. It's quick & easy.

If it looks like a bug acts like a bug ...

P: n/a

I say its a bug. What do you think?

public class test
public static void main(String args)

int n
Integer I

I = new Integer(0)
for (int i = 0 i < 5 i++)
System.out.println("n = "+I)
n = I.intValue()
I = new Integer(n+1) //increment//
I = new Integer(0)
for (int i = 0 i < 5 i++)
System.out.println("n = "+I)
n = I.intValue()
I = new Integer(n++) //increment//



P.S. Thank you, Raymond DeCampo, for you help with the porxyHost System propery problem.

Jul 17 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Nomen Nescio wrote:
I say its a bug. What do you think?

public class test
public static void main(String args)

int n
Integer I

I = new Integer(0)
for (int i = 0 i < 5 i++)
System.out.println("n = "+I)
n = I.intValue()
I = new Integer(n+1) //increment//
I = new Integer(0)
for (int i = 0 i < 5 i++)
System.out.println("n = "+I)
n = I.intValue()
I = new Integer(n++) //increment//


This isn't Java code. Why don't you post some actual code, and then
explain how its behavior differs from what you expect?

For example, if it turns out that you expect the post-increment (n++) to
have the value of n after the increment, then someone here can explain
why that expectation is incorrect, and why you might find the
pre-increment operator (++n) more appropriate to the situation.
Jul 17 '05 #2

P: n/a
On Thu, 29 Apr 2004 17:50:02 +0200 (CEST), Nomen Nescio wrote:

Sub: If it looks like a bug acts like a bug ...
...it is probably a noob error.

[F'ups set to c.l.j.h, the only one
of the three groups to which you
cross-posted that is actually valid. ]
I say its a bug. What do you think?


Wot? You mean the way your copy paste
seems to lose the {}, ; and []?

Definitely, lose that editor immediately!

I have no idea what you think the bug is,
since you did not say, (and my crystal
ball is out for cleaning) but it may have
something to do with your confusion between
the upper and lower case 'I/i', which you
seem to use interchangeably.

Try this variant.
<code>
public class TestBug
{
public static void main(String[] args) {
int n;

for (int i = 0; i < 5; i++)
System.out.println("n = "+ i);

for (int i = 0; i < 5; i++)
System.out.println("n = "+ i);
}
}
</code>

Next time you discover a 'bug', I recommend
you post _only_ to c.l.j.help with a title
to the effect 'cannot understand why this code..'

And please be specific..
- I expect this output beacuse of a, b and c
- _Instead_ I get _this_ output..

HTH

--
Andrew Thompson
http://www.PhySci.org/ Open-source software suite
http://www.PhySci.org/codes/ Web & IT Help
http://www.1point1C.org/ Science & Technology
Jul 17 '05 #3

P: n/a
I *think* that Nomen is referring to the apparent "bug" where:
int i=0;
foo(i+1); // run's foo(1)
foo(i++); // run's foo(0)

But it's not a bug, since after foo(i+1), i is still 0. And
foo(i++) means "run foo(i), then increment i"

At least, that's what I think he meant.

Mike Scovetta

Nomen Nescio <no****@dizum.com> wrote in message news:<e7******************************@dizum.com>. ..
I say its a bug. What do you think?

public class test
public static void main(String args)

int n
Integer I

I = new Integer(0)
for (int i = 0 i < 5 i++)
System.out.println("n = "+I)
n = I.intValue()
I = new Integer(n+1) //increment//
I = new Integer(0)
for (int i = 0 i < 5 i++)
System.out.println("n = "+I)
n = I.intValue()
I = new Integer(n++) //increment//



P.S. Thank you, Raymond DeCampo, for you help with the porxyHost System propery problem.

Jul 17 '05 #4

P: n/a
Nomen Nescio wrote:

I say its a bug. What do you think?

I say that:
0. It's conventional to start the name of a class with a capital letter
(Test not test).
1. This doesn't look like Java. Where are the semicolons and the curly
brackets? Not that I miss the ugly little bastards, it's just that with out
them it's not Java.
2. You don't say what output your test program produces, not what you
expect. That makes it hard to see where the bug might lie.
3. In the second loop, writing n++ is pointless; n++ increments n, but
passes the old value of n to the surrounding context, not the new one. So
the new Integer you assign to I in the last line is identical to the one it
is replacing, and the incremented value of n is never used (if you go
around the loop again then n is re-assigned before it is used again).
public class test
public static void main(String args)

int n
Integer I

I = new Integer(0)
for (int i = 0 i < 5 i++)
System.out.println("n = "+I)
n = I.intValue()
I = new Integer(n+1) //increment//
I = new Integer(0)
for (int i = 0 i < 5 i++)
System.out.println("n = "+I)
n = I.intValue()
I = new Integer(n++) //increment// Interpreting this to mean:
public class test {
public static void main(String args[]) {

int n;
Integer I;

I = new Integer(0);
for (int i = 0; i < 5; i++) {
System.out.println("n = "+I);
n = I.intValue();
I = new Integer(n+1); //increment//
}
I = new Integer(0);
for (int i = 0; i < 5; i++) {
System.out.println("n = "+I);
n = I.intValue();
I = new Integer(n++); //increment//
}
}
}

I get the output:
n = 0
n = 1
n = 2
n = 3
n = 4
n = 0
n = 0
n = 0
n = 0
n = 0

If you were expecting something else then yes, your program is buggy.

P.S. Thank you, Raymond DeCampo, for you help with the porxyHost System
propery problem.


--
Chris Gray ch***@kiffer.eunet.be
/k/ Embedded Java Solutions

Jul 17 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.