Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > my thread of basic Java questions

Reply
Thread Tools

my thread of basic Java questions

 
 
denim_genes@hotmail.com
Guest
Posts: n/a
 
      04-13-2008
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.
 
Reply With Quote
 
 
 
 
Mark Space
Guest
Posts: n/a
 
      04-13-2008
http://www.velocityreviews.com/forums/(E-Mail Removed) 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.

 
Reply With Quote
 
 
 
 
denim_genes@hotmail.com
Guest
Posts: n/a
 
      04-13-2008
On Apr 13, 12:18 am, Mark Space <(E-Mail Removed)> wrote:
> (E-Mail Removed) 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 ?
 
Reply With Quote
 
Mark Space
Guest
Posts: n/a
 
      04-13-2008
(E-Mail Removed) wrote:
> On Apr 13, 12:18 am, Mark Space <(E-Mail Removed)> wrote:
>> (E-Mail Removed) 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)

 
Reply With Quote
 
denim_genes@hotmail.com
Guest
Posts: n/a
 
      04-13-2008
On Apr 13, 2:18 am, Mark Space <(E-Mail Removed)> wrote:
> (E-Mail Removed) wrote:
> > On Apr 13, 12:18 am, Mark Space <(E-Mail Removed)> wrote:
> >> (E-Mail Removed) 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.
 
Reply With Quote
 
Arved Sandstrom
Guest
Posts: n/a
 
      04-13-2008
"Mark Space" <(E-Mail Removed)> wrote in message
news:NAhMj.5686$(E-Mail Removed)...
> (E-Mail Removed) wrote:
>> On Apr 13, 12:18 am, Mark Space <(E-Mail Removed)> wrote:
>>> (E-Mail Removed) 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


 
Reply With Quote
 
Chase Preuninger
Guest
Posts: n/a
 
      04-13-2008
don't you need a boolean or something that can be converted to a
boolean by the compiler for that to work?
 
Reply With Quote
 
Arne Vajh°j
Guest
Posts: n/a
 
      04-13-2008
(E-Mail Removed) 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
 
Reply With Quote
 
Arne Vajh°j
Guest
Posts: n/a
 
      04-13-2008
Arne Vajh°j wrote:
> (E-Mail Removed) 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
 
Reply With Quote
 
denim_genes@hotmail.com
Guest
Posts: n/a
 
      04-13-2008
On Apr 13, 11:51 am, Arne Vajh°j <(E-Mail Removed)> wrote:
> Arne Vajh°j wrote:
> > (E-Mail Removed) 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Java xml basic questions Rolf.Kemper@eu.necel.com Java 4 05-02-2007 02:02 PM
Clicking on Sun Java Plugin installation evokes 3 basic java setup questions Bonnie Johnson Java 2 01-10-2007 10:13 AM
Java install on Linux FC4 (Two very basic questions). AnonymousFC4 Java 3 07-29-2005 12:05 AM
Re: Questions....questions....questions Patrick Michael A+ Certification 0 06-16-2004 04:53 PM
Upgrading Microsoft Visual Basic 6.0 to Microsoft Visual Basic .NET Jaime MCSD 2 09-20-2003 05:16 AM



Advertisments