public class aa {
public static void main(String[] args) {
int number = 521;
String temp1 = "" + number;
int result = 0;
int[] temp2 = new int[temp1.length()];
for(int i=0; i<temp1.length(); i++){
int len = temp1.length();
temp2[i] = temp1.charAt(len-i-1);
System.out.println(temp2[i]);
System.out.println(temp1.charAt(len-i-1));
}
}
}
This program should make 521 to 125 (reverse). But when I run this program, the result is
49
1
50
2
53
5
I think that string value is right, but when I add that string value to array, it goes wrong way. Can some one tell me what is wrong?
printlnprints a newline at the end of it output, so there's no way your output will be on one line only if you use that. Second,temp2is an array ofints, you can't expectprintlnto know you actually wantedchars if you ask it to print numbers.