string printing converted to numbers while using ".charAt(1)+.chatAt(2)"
Hi,
I'm back I was to exams, My project is over.. thanks to the moderators..
My coding is
Code:
public class stringing {
public static void main(String[] args)
{
String a=new String("bcaefdhigklj");
for(int i=0;i<a.length();i=i+3)
{
//System.out.println(a.charAt(i+1)+"\n");//here it works fine
System.out.println(a.charAt(i+1)+a.charAt(i+2)+a.charAt(i)+"\n");
//but here it prints numbers
}
}
}
output:
regards
dhilip
Re: string printing converted to numbers while using ".charAt(1)+.chatAt(2)"
When you concatenate chars using the (+) operator the value will be converted into the ASCII code that represent the char. For instance a = 97; b = 98; c = 99, etc. To make it concatenate as a string you need to convert the chars into string. The simplest way is to concatenate a string with it, you can write it like:
Code:
System.out.println("" + a.charAt(i + 1) + a.charAt( i + 2) + a.charAt(i));
Re: string printing converted to numbers while using ".charAt(1)+.chatAt(2)"