![]() |
my thread of basic Java questions
Why is the following true?:
(ok || (n1 < 0)) And what the heck is "ok"? My guess: any String or character or whatever is "true" on its own, since it exists. Thus, "ok" could be replaced by "dinosaur", and the answer to the question would still be true. |
Re: my thread of basic Java questions
denim_genes@hotmail.com wrote:
> Why is the following true?: > > (ok || (n1 < 0)) > > And what the heck is "ok"? > > My guess: any String or character or whatever is "true" on its own, > since it exists. Thus, "ok" could be replaced by "dinosaur", and the > answer to the question would still be true. It isn't true, and strings in Java have double quotes around them. ok is obviously a variable that's been declared elsewhere, just like n1. |
Re: my thread of basic Java questions
On Apr 13, 12:18 am, Mark Space <marksp...@sbc.global.net> wrote:
> denim_ge...@hotmail.com wrote: > > Why is the following true?: > > > (ok || (n1 < 0)) > > > And what the heck is "ok"? > > > My guess: any String or character or whatever is "true" on its own, > > since it exists. Thus, "ok" could be replaced by "dinosaur", and the > > answer to the question would still be true. > > It isn't true, and strings in Java have double quotes around them. > > ok is obviously a variable that's been declared elsewhere, just like n1. It's true... I'm looking at the answer key right now... int dinosaur = 0; dinosaur == true ? |
Re: my thread of basic Java questions
denim_genes@hotmail.com wrote:
> On Apr 13, 12:18 am, Mark Space <marksp...@sbc.global.net> wrote: >> denim_ge...@hotmail.com wrote: >>> Why is the following true?: >>> (ok || (n1 < 0)) >>> And what the heck is "ok"? >>> My guess: any String or character or whatever is "true" on its own, >>> since it exists. Thus, "ok" could be replaced by "dinosaur", and the >>> answer to the question would still be true. >> It isn't true, and strings in Java have double quotes around them. >> >> ok is obviously a variable that's been declared elsewhere, just like n1. > > It's true... I'm looking at the answer key right now... > > int dinosaur = 0; > > dinosaur == true ? It's false. I don't care about your answer key. Get a compiler and try it, or better yet learn the language. Your latest one here is wrong too, ints aren't even comparable to booleans.: init: deps-jar: Compiling 1 source file to C:\Users\Brenden\Dev\misc\FinalizeTest\build\class es C:\Users\Brenden\Dev\misc\FinalizeTest\src\finaliz etest\Main.java:31: incomparable types: int and boolean if( dinosaur == true ) 1 error BUILD FAILED (total time: 2 seconds) |
Re: my thread of basic Java questions
On Apr 13, 2:18 am, Mark Space <marksp...@sbc.global.net> wrote:
> denim_ge...@hotmail.com wrote: > > On Apr 13, 12:18 am, Mark Space <marksp...@sbc.global.net> wrote: > >> denim_ge...@hotmail.com wrote: > >>> Why is the following true?: > >>> (ok || (n1 < 0)) > >>> And what the heck is "ok"? > >>> My guess: any String or character or whatever is "true" on its own, > >>> since it exists. Thus, "ok" could be replaced by "dinosaur", and the > >>> answer to the question would still be true. > >> It isn't true, and strings in Java have double quotes around them. > > >> ok is obviously a variable that's been declared elsewhere, just like n1. > > > It's true... I'm looking at the answer key right now... > > > int dinosaur = 0; > > > dinosaur == true ? > > It's false. I don't care about your answer key. Get a compiler and try > it, or better yet learn the language. > > Your latest one here is wrong too, ints aren't even comparable to booleans.: > > init: > deps-jar: > Compiling 1 source file to > C:\Users\Brenden\Dev\misc\FinalizeTest\build\class es > C:\Users\Brenden\Dev\misc\FinalizeTest\src\finaliz etest\Main.java:31: > incomparable types: int and boolean > if( dinosaur == true ) > 1 error > BUILD FAILED (total time: 2 seconds) I know the language, hence why I was confused as to this "reliable" answer key. |
Re: my thread of basic Java questions
"Mark Space" <markspace@sbc.global.net> wrote in message
news:NAhMj.5686$GE1.2828@nlpi061.nbdc.sbc.com... > denim_genes@hotmail.com wrote: >> On Apr 13, 12:18 am, Mark Space <marksp...@sbc.global.net> wrote: >>> denim_ge...@hotmail.com wrote: >>>> Why is the following true?: >>>> (ok || (n1 < 0)) >>>> And what the heck is "ok"? >>>> My guess: any String or character or whatever is "true" on its own, >>>> since it exists. Thus, "ok" could be replaced by "dinosaur", and the >>>> answer to the question would still be true. >>> It isn't true, and strings in Java have double quotes around them. >>> >>> ok is obviously a variable that's been declared elsewhere, just like n1. >> >> It's true... I'm looking at the answer key right now... >> >> int dinosaur = 0; >> >> dinosaur == true ? > > It's false. I don't care about your answer key. Get a compiler and try > it, or better yet learn the language. > > Your latest one here is wrong too, ints aren't even comparable to > booleans.: [ SNIP ] This question brings up the always popular programming trivia contest...what are the truth values in various programming languages? Not always easy to remember... For example, in awk "0" is true because it's a non-null string value. However, in Perl "0" is false (but "0.0" is true). Apparently in REBOL the integer 0 is true. Does the language in question (1) use two boolean values, or (2) does it define truth values for all values of datatypes, or (3) does it define two boolean values *and* also truth values for values of other datatypes? Example of #3 being Javascript. Then there's the convention in UNIX that a program is considered to have succeeded if it sets an exit code of 0, which can catch the novice shell script programmer by surprise... I think there was an attempt to design a bool class in C++ quite some back but they couldn't quite design one that was completely correct, hence the bool datatype. Of course you can still initialize a bool with 0... AHS |
Re: my thread of basic Java questions
don't you need a boolean or something that can be converted to a
boolean by the compiler for that to work? |
Re: my thread of basic Java questions
denim_genes@hotmail.com wrote:
> Why is the following true?: > > (ok || (n1 < 0)) > > And what the heck is "ok"? > > My guess: any String or character or whatever is "true" on its own, > since it exists. Thus, "ok" could be replaced by "dinosaur", and the > answer to the question would still be true. What is ok declared as ? Arne |
Re: my thread of basic Java questions
Arne Vajhøj wrote:
> denim_genes@hotmail.com wrote: >> Why is the following true?: >> >> (ok || (n1 < 0)) >> >> And what the heck is "ok"? >> >> My guess: any String or character or whatever is "true" on its own, >> since it exists. Thus, "ok" could be replaced by "dinosaur", and the >> answer to the question would still be true. > > What is ok declared as ? And what is its value ? Arne |
Re: my thread of basic Java questions
On Apr 13, 11:51 am, Arne Vajhøj <a...@vajhoej.dk> wrote:
> Arne Vajhøj wrote: > > denim_ge...@hotmail.com wrote: > >> Why is the following true?: > > >> (ok || (n1 < 0)) > > >> And what the heck is "ok"? > > >> My guess: any String or character or whatever is "true" on its own, > >> since it exists. Thus, "ok" could be replaced by "dinosaur", and the > >> answer to the question would still be true. > > > What is ok declared as ? > > And what is its value ? > > Arne boolean ok = true; int n1 = 100; int n2 = 0; They forgot to put that in the question. I guess it makes sense now. |
| All times are GMT. The time now is 07:56 PM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.