![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#11 |
|
Caffeinated Neural Net
Join Date: Jun 2005
Location: Wet west coast of Canada
Posts: 889
Rep Power: 4
![]() |
Yes, you've got it, except Java does not interpret 01000000 as being true. You need an explicit comparison when testing any value that is not boolean. Otherwise, you get a compiler error:
int flag = 0;
if(flag != 0)
System.println("flag is nonzero");
if(flag) // error
System.println("flag is nonzero");if(flag == true) // error
System.println("flag is nonzero");
__________________
A man's knowledge is like an expanding sphere, the surface corresponding to the boundary between the known and the unknown. As the sphere grows, so does its surface; the more a man learns, the more he realizes how much he does not know. Hence, the most ignorant man thinks he knows it all. - L. Sprague de Camp |
|
|
|
|
|
#12 |
|
Hobbyist Programmer
Join Date: Mar 2005
Posts: 148
Rep Power: 4
![]() |
Kinda confusing. In C++ any non-zero integer means true, and zero means false. I think I did read in one of my books about Java that in Java the zero does not mean false and any non-zero integer does not necessarily mean true. I thought the if statement always tests for truth. So if I did this in Java:
int x = 1;
if (x)
System.out.print("Welcome home.");
else
System.out.print("Go away.");That would be wrong? I would have to say: int x = 1;
if (x == 1)
System.out.print("Welcome home.");
else
System.out.print("Go away.");I'm going to have to play around with this stuff. |
|
|
|
|
|
#13 |
|
Hobbyist Programmer
Join Date: Mar 2005
Posts: 148
Rep Power: 4
![]() |
So just by itself, the result 1000 0000 doesn't necessarily mean true to Java. You have to go one step further and include a comparison operator in your if statement like this:
if (result != 0)
System.out.print("This line will execute.");
else
System.out.print("You won't see this.");The end result of explicitly adding the != operator to your if statement is that Java will actually compare the result(1000 0000) to 0(!= 0) and then the end result of that will in fact be either a true or a false, meaning the outcome will be in fact a boolean value. Then the compiler will go ahead and execute the appropriate line. God I hope I got this correct. |
|
|
|
|
|
#14 | |
|
Caffeinated Neural Net
Join Date: Jun 2005
Location: Wet west coast of Canada
Posts: 889
Rep Power: 4
![]() |
Quote:
__________________
A man's knowledge is like an expanding sphere, the surface corresponding to the boundary between the known and the unknown. As the sphere grows, so does its surface; the more a man learns, the more he realizes how much he does not know. Hence, the most ignorant man thinks he knows it all. - L. Sprague de Camp |
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Attitudes | Oddball | Coder's Corner Lounge | 29 | Mar 18th, 2006 9:34 PM |
| C++ template and namespace question | Soulstorm | C++ | 3 | Jan 22nd, 2006 2:46 PM |
| How to post a question | nnxion | C++ | 10 | Jun 3rd, 2005 11:53 AM |
| How to post a question | nnxion | C++ | 0 | Jun 3rd, 2005 8:55 AM |
| How to post a question | nnxion | C | 0 | Jun 3rd, 2005 8:55 AM |