![]() |
Whats wrong with newb code?
:
import java.io.* ;Im doing aome programming exercises. This one is supposed to accept input and output. It prints the number and closes when 42 is entered. Looks good to me, but it wont let me compile gives some ridiculous error messages. Any help? |
What are you trying to achieve here:
:
In the future you should post the line and text of the error messages. |
I fixed up your code. If you have any questions, feel free to ask.
:
import java.io.*; |
(!(a <= 0) || !(a >= 0))
I still understand that statement. It's saying if this number is not less or equal to zero or this number is not greater or equal to zero. Tell me a number that would fit that description! |
Well, just simplify the statement:
!(a <= 0) || !(a >= 0) a > 0 || a < 0 a != 0 Hence, 0 would fit that description. :) |
Awwwh, I see! lol :beard:
EDIT: Why the f*ck would anyone write it like that anyways? I never seen that before! |
Attaboy, Titanium; boolean algebra/DeMorgan's Theorem isn't just for gate-slinging hardware weenies. However, non-zero 'a' gives the true evaluation.
@king: a simplification often makes the original expression look silly, as in this case. There are cases, however, where the tested values might be coming from a port in inverted form or some other weird combination. Devising an exclusive-nor (if one doesn't have an exclusive-or instruction) can actually be done in fewer steps if one complicates the expression. |
It's good practice to have decent code structure and organization. It makes reading code and distinguishing ends of operations easier. For example, your { 's should line up with the corresponding if, class, or while operation. As seen in titaniumdecoy's code, it's organized and easy to read.
On a side note, you code in an abstract way that seems to branch from the objective. I think you need to focus or fully understand what you intend to do and how. |
Quote:
But thanks, and everyone who helped thank you too. |
| All times are GMT -5. The time now is 4:04 PM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC