题目:
-
细节:输入int,放回String
class IntegerReverseOrder{
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int number = input.nextInt();
String s = String.valueOf(number); // int整数 变成 String字符串
int[] intArray = new int[s.length()];
int[] newArray = new int[s.length()];
for (int i = 0; i < s.length(); i++) {
intArray[i] = Integer.parseInt(String.valueOf(s.charAt(i)));
}
inversionArray(intArray,newArray);
//System.out.println(Arrays.toString(newArray));
String[] stringArray = new String[newArray.length]; //String字符串
for (int i = 0; i < newArray.length; i++) {
stringArray[i] = Integer.toString(newArray[i]);
}
String result = "";
//System.out.println(Arrays.toString(stringArray));
for (int i = 0; i < stringArray.length; i++) {
result += stringArray[i];
}
System.out.println(result);
input.close();
}
//int数组反转
public static void inversionArray(int[] l_old, int[] l_new) {
int length = l_old.length;//获得"原数组"的长度
for (int i = 0; i < l_old.length; i++) {
l_new[length - 1] = l_old[i]; //新数组的最后一个 == 原数组第一个
length--;
}
}
}
标签:String,int,整数,length,newArray,new,stringArray,逆序
From: https://www.cnblogs.com/chen-zhou1027/p/17418852.html