473,396 Members | 1,893 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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


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
4 1925
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

53
by: Paul Rubin | last post by:
I've been approached about writing a Windows app which will need a really professional looking GUI. Forget TKinter, this has to actually look good (real artists will be available to get the visual...
354
by: Montrose... | last post by:
After working in c# for a year, the only conclusion I can come to is that I wish I knew c. All I need is Linux, the gnu c compiler and I can do anything. Web services are just open sockets...
2
by: Patrick | last post by:
I want a Windows Forms DataGrid that acts in some ways like a ListBox. It should behave like this: -> When you click on a cell, the entire row is highlighted (instead of just the contents of the...
2
by: Gregory Gadow | last post by:
The TabControl that shipped with .NET 2.0 is seems to be buggier than dog droppings in high summer. Among several complaints, the tabs themselves look horrifically ugly when their pages have the...
3
by: ashkaan57 | last post by:
Hi, I have a page that looks crooked in Firefox but displays normally in IE. http://www.legalpersian.com The page was designed using Visual Web Developer 2005 (part of MS Vsual Studio 2005...
2
by: johnny15 | last post by:
My website www.windsoraccess.co.uk looks different in IE to Firefox at the very top where my logo and wording is. In IE the gap surrounding the logo and wording is much less and looks absolutely...
2
by: Jim | last post by:
Hello, I need a program that will traverse a directory tree to ensure that there are unix-style line endings on every file in that tree that is a text file. To tell text files from others I...
5
by: david | last post by:
I have a picture and it has onclick event, with invokes JavaScript function called ModuleManager(); Then it saves a copy of Node (Blocks, which is DIV) it tmp_blocks with all children elements. And...
6
by: Rafe | last post by:
Forgive me if I mangle any terminology here, but please correct me if I do... I have an object which acts exactly like a string as long as I stay in Python land. However, I am using the object...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.