adding integers to strings

is there a way to put integers in strings?

like in the following script putting the string values in characters is there a way to put in numbers instead?

class Sid {

public static void main(String[] arguments) {

String heads = "tweleve";

String noses = "thirteen";

String organs = "zero";

String guess = "twenty-five";

System.out.println("you have " + heads + " heads and " + noses + " noses");

System.out.println("The computer guesses you have " + guess + " limbs");

organs = "twenty-five";

System.out.println("Answer: \n\t" + organs.equals(guess));

System.out.println("in total you have:\n\t twenty-five limbs!");

System.out.println("hmm.. how many characters are there in twenty-five?");

int length = organs.length();

System.out.println("there are " + length + " charachters in " + organs);

}

}

[906 byte] By [javaa] at [2007-11-26 15:25:42]
# 1
Yes.String answer = "137";
DrClapa at 2007-7-8 21:41:19 > top of Java-index,Java Essentials,Java Programming...
# 2

Since everything is hard-coded anyway, just hardcode numbers.

You might want to think about storing all numbers in numeric-typed variables (like, ints) and then, if you really need numbers spelled out textually, pass them through a utility method to translate numbers to text descriptions of numbers immediately prior to output.

paulcwa at 2007-7-8 21:41:19 > top of Java-index,Java Essentials,Java Programming...
# 3
Or, if you have an int primitive,int nbr = 3;then Integer.toString(nbr)returns a String "3"(as Paul just said)Message was edited by: ChuckBing
ChuckBinga at 2007-7-8 21:41:19 > top of Java-index,Java Essentials,Java Programming...