• Post Reply Bookmark Topic Watch Topic
  • New Topic

Hold char and integer in one variable  RSS feed

 
amir asyraf
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
is there any best practice that i can follow, where i can hold the character and integer in one variable ? and let say, if i can.. can i make it as array ?


the output need to shown as (something like this) :

*
?
1
2
3
4
5
6
7
8
9
10
 
Tim Moores
Saloon Keeper
Posts: 4036
94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could use a java.util.ArrayList<Object>.
 
Campbell Ritchie
Marshal
Posts: 56584
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
amir asyraf wrote:is there any best practice that i can follow, where i can hold the character and integer in one variable ?  . . .
No. You can either store the numeric value of a char in 16 bits, or you can store the numeric value as an int in 32 bits, but not both in the same variable. Nor as elements of the same array. Also if you find a value like 0x21 (decimal 33), and you look it up as 21 on an ASCII/basic Unicode table, how are you going to know whether to display 33 or ! ?
But your output isn't made of characters at all. It is an output of multiple Strings, so why not declare your variables as Strings and they will be easy to handle.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!