d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Programming Questions - Continuous
Add Reply New Topic New Poll
Member
Posts: 10,049
Joined: Aug 11 2014
Gold: 540.00
Oct 22 2015 05:22pm
instead of making multiple threads every time I have a small question, I'm just going to post questions here (or anyone could too).


for(x=0;x<3;x++)
{
System.out.println("do you want met o draw a simple house for you? ");
answer=keyboard.next();

if(answer==yes)
good=true;

else if(answer==no)
end=true;
}


it's as if it completely ignores the 2 if statements (I initialized the variables). Is my syntax wrong? Thank you
Member
Posts: 23,862
Joined: Aug 16 2006
Gold: 20.00
Oct 22 2015 06:09pm
is that the EXACT code? line by line?


If not, you need to post ALL of the code, exactly as it appears in your source. Also, make sure to use code tags for formatting and readability

Code
this is a code tag


This post was edited by Eep on Oct 22 2015 06:10pm
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Oct 22 2015 06:39pm
i assume those are strings. use .equals instead of ==

== works ok when comparing literals, but reading input from keyboard isn't a literal.
Member
Posts: 10,049
Joined: Aug 11 2014
Gold: 540.00
Oct 22 2015 07:19pm
Quote (Eep @ Oct 22 2015 08:09pm)
is that the EXACT code? line by line?


If not, you need to post ALL of the code, exactly as it appears in your source. Also, make sure to use code tags for formatting and readability

Code
this is a code tag


That's part of the code, I didn't want to post all of it and make it look complicated for you guys, but yes carteblanche gave me the answer thank you. And yea next time I'll use the quote format thanks.

Quote (carteblanche @ Oct 22 2015 08:39pm)
i assume those are strings. use .equals instead of ==

== works ok when comparing literals, but reading input from keyboard isn't a literal.


Thank you!
Member
Posts: 29,351
Joined: Mar 27 2008
Gold: 504.69
Oct 23 2015 04:41am
Quote (carteblanche @ Oct 22 2015 08:39pm)
i assume those are strings. use .equals instead of ==

== works ok when comparing literals, but reading input from keyboard isn't a literal.


This. Iirc corretly what you were actually comparing to there was the location address of your string.
Member
Posts: 10,049
Joined: Aug 11 2014
Gold: 540.00
Oct 28 2015 09:58pm
hello,
let's say i create a 2D integer array for tictactoe in this format:

Code
int tictactoe[][]={{1,2,3},{4,5,6},{7,8,9}};


how would I be able to insert the X or the O as characters? It prints it as the unicode value

thanks

This post was edited by kyle_lowry2 on Oct 28 2015 09:58pm
Member
Posts: 29,351
Joined: Mar 27 2008
Gold: 504.69
Oct 29 2015 05:25am
Quote (kyle_lowry2 @ Oct 28 2015 11:58pm)
hello,
let's say i create a 2D integer array for tictactoe in this format:

Code
int tictactoe[][]={{1,2,3},{4,5,6},{7,8,9}};


how would I be able to insert the X or the O as characters? It prints it as the unicode value

thanks


Characters can be referenced by integers and it will return a character based on the unicode value.

There is a primitive data type for characters.
https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html

This post was edited by ROM on Oct 29 2015 05:26am
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll