Author |
Message |
ahmhum
|
Posted: Sun Apr 12, 2009 7:38 pm Post subject: converting int to string |
|
|
Ok I'm trying to convert int to string and i dun know how to, so plzz help me out
here is wat im tryin to convert
Java: | /*This method allows the user to choose which style of face he/she wants for
the Death God.*/
public static void faceQuestion (int sword )
{
//Clear screens.
d. clear();
c. clear();
//String face;
//Call upon the various initial setup methods.
{
backgroundC (x,y );
backgroundForDConsole (x, y );
textBoxForTitles ();
faceTitle ();
constructBoxLeftSide ();
constructBoxRightSide ();
constructCircleLeftSide ();
constructCircleRightSide ();
face1stOption ();
face2ndOption ();
}
//Calling upon the faceConstruct method.
{
faceConstruct ();
}
//Call upon the grid method.
{
grid ();
}
//Ask user first question.
d. setTextBackgroundColor(Color. black);
d. println(" Please choose your Death God's face type:");
d. println("----------------------------------------------------------------------------------------------------");
d. println("* Please enter: *");
d. println("* (1) for Human Face *");
d. println("* (2) for Hollow Face *");
d. println("* (-1) to return to previous screen. *");
d. println("----------------------------------------------------------------------------------------------------");
d. print(" Please enter your choice now: ");
//Read input.
String input = d. readLine();
//Set integers.
int face= 0;
/* Set up 'if' construct with try/catch to determine the
next choice of action for the user.*/
try
{
face= Integer. parseInt(input );
}
catch (NumberFormatException e )
{
//User selects defaults to invalid entry.
}
if (face== 1)
{
//Calling upon the hair method.
hairQuestion (sword, face );
}
if (face== 2)
{
//Calling upon the hair method.
hairQuestion (sword, face );
}
if (face==- 1)
{
swordQuestion ();
}
if (- 1>face||face== 0||face> 2)
{
//Call upon invalid entry.
invalidEntry ();
//Creating the loop.
faceQuestion (face );
}
} //faceQuestion method
|
so instead of it being face == 1 i want it to be 1A or 1B and so on
thnx in advance
Mod Edit: Remember to use syntax tags! Thanks code: | [syntax="java"]Code Here[/syntax] |
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
Dark
|
Posted: Sun Apr 12, 2009 9:33 pm Post subject: RE:converting int to string |
|
|
Didn't read your code but this is how to convert an int to a string.
In case you are wondering on how to convert a char value into a String,
|
|
|
|
|
|
ahmhum
|
Posted: Sun Apr 12, 2009 10:10 pm Post subject: RE:converting int to string |
|
|
it doesn't work even when i did that |
|
|
|
|
|
ahmhum
|
Posted: Sun Apr 12, 2009 10:20 pm Post subject: RE:converting int to string |
|
|
ok nvm it did work |
|
|
|
|
|
ahmhum
|
Posted: Sun Apr 12, 2009 10:37 pm Post subject: RE:converting int to string |
|
|
ok now i want to convert char value to String but what you told me to do Dark, it doesn't work |
|
|
|
|
|
Dusk Eagle
|
Posted: Sun Apr 12, 2009 10:38 pm Post subject: Re: converting int to string |
|
|
Just out of curiosity, are you making a Death Note game? |
|
|
|
|
|
Tony
|
Posted: Sun Apr 12, 2009 10:51 pm Post subject: RE:converting int to string |
|
|
You'd think that he'd actually use "Shinigami" then. The reference to "Hollow" makes me think Bleach, although I haven't seen nearly enough of that series to be sure.
@ahmhum -- in what way does it not work? |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
ahmhum
|
Posted: Sun Apr 12, 2009 10:57 pm Post subject: RE:converting int to string |
|
|
it says tht the char is not defined
char c = 'k';
String value = Character.toString(c);
so (c) is not defined is what i get
nd yea its a bleach game |
|
|
|
|
|
Sponsor Sponsor
|
|
|
ahmhum
|
Posted: Sun Apr 12, 2009 11:00 pm Post subject: RE:converting int to string |
|
|
oo and i want it to read two character so like 1A and not just 1 or A or w/e |
|
|
|
|
|
ahmhum
|
Posted: Mon Apr 13, 2009 12:11 am Post subject: RE:converting int to string |
|
|
ok this is what I want to convert from char to String
Java: | //Allow user to input number to see an object.
public static void player1Choose (String namePlayer1, String namePlayer2 )
{
e. clear();
d. clear();
//Set integers for choose selection.
int number;
int input= 0;
//Prompt user to input data and read the character.
player1ChooseText (namePlayer1 );
backgroundForEConsole ();
itsYourTurnText (e );
makeAMoveText (e );
e. setTextColor(Color. white);
e. setTextBackgroundColor(Color. blue);
e. println(namePlayer1+ " Your score is: "+scorePlayer1+ "");
char play = d. getChar();;
if (play == '1')
{
input = 1;
}
if (play == '2')
{
input = 2;
}
if (play == '3')
{
input = 3;
}
if (play == '4')
{
input = 4;
}
if (play == '5')
{
input = 5;
}
if (play == '6')
{
input = 6;
}
if (play == '7')
{
input = 7;
}
if (play == '8')
{
input = 8;
}
if (play == '9')
{
input = 9;
}
e. clear();
d. clear();
//Set number selection.
number=input;
//Try/catch construct for invalid entry.
try
{
numberForPlayer1 (number,namePlayer1,namePlayer2 );
}
catch (NumberFormatException e )
{
invalidEntry ();
gameGrid ();
player1Choose (namePlayer1,namePlayer2 );
}
}//choose method
|
thnx in advance |
|
|
|
|
|
Tony
|
Posted: Mon Apr 13, 2009 12:29 am Post subject: RE:converting int to string |
|
|
code: |
if (play == '1')
{
input = 1;
}
if (play == '2')
...
|
No. |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
ahmhum
|
Posted: Mon Apr 13, 2009 1:20 am Post subject: RE:converting int to string |
|
|
what do u mean no |
|
|
|
|
|
wtd
|
Posted: Mon Apr 13, 2009 2:17 am Post subject: RE:converting int to string |
|
|
He means that's the wrong way to write that bit of code.
Notice the pattern. Make your code simpler. |
|
|
|
|
|
wtd
|
Posted: Mon Apr 13, 2009 2:19 am Post subject: RE:converting int to string |
|
|
Also horribly wrong:
code: | if (face==1)
{
//Calling upon the hair method.
hairQuestion(sword, face);
}
if (face==2)
{
//Calling upon the hair method.
hairQuestion(sword, face);
} |
|
|
|
|
|
|
Dark
|
Posted: Mon Apr 13, 2009 10:05 am Post subject: RE:converting int to string |
|
|
those should be else ifs, after the first if.
Also, use a switch statement for those ifs.
Or, better yet, let play = input.
parse the char into an int. |
|
|
|
|
|
|