• Post Reply Bookmark Topic Watch Topic
  • New Topic

how to convert int and get char value  RSS feed

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have tried type casting but its giving me a blank print

int[] name = new int[2];
char[] values = new char[2];

name[1] =23;
name[2]=13;

for(int index =0; index < name.length -1; index++)
{
values[index] =(char) name[index];
System.out.println(values[index]);
}

Is they any other way to get the character values of the integers 23, 13
 
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What exactly are you expecting to see when you print out 13 and 23? For instance, 13 is a carriage return. It's not going to be visible.
 
danny dich
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm expecting to get a character such (A) which will be the converted value of lets say 13
 
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
danny dich wrote:I'm expecting to get a character such (A) which will be the converted value of lets say 13



An "A" has a value of 65. So, if you expect an "A", you need to adjust your int values accordingly.

Henry
 
Marshal
Posts: 56608
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As you will see here, you won't get A from 13. Remember the numbers given there are hexadecimal.
 
Matthew Brown
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's another table: http://www.asciitable.com/. Anything that's a control character (all the first column) is unlikely to be visible when you print it out.
 
danny dich
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you that was very helpful.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!