将整数m的各位数字保存到数组A中

时间:2021-03-15 08:18:37
import java.util.Scanner;

/**
* @author:(LiberHome)
* @date:Created in 2019/3/4 20:10
* @description:
* @version:$
*/
/*将整数m的各位数字保存到数组A中*/
public class page1102 {
public static void main(String[] args) {
/*首先,确定数组的长度*/
System.out.println("请输入一个整数");
Scanner scanner = new Scanner(System.in);
int inputNum = scanner.nextInt();
int size = 1;
int temp = inputNum;
while (temp / 10 != 0) {
size++;
temp = temp / 10;
}
/*新建一个数组A,挨个赋值*/
int[] A = new int[size];
for (int i = 0; i < size && inputNum / 10 != 0; i++) {
A[i] = inputNum % 10;
inputNum/=10;
if (inputNum<10){
A[i+1]=inputNum;
}
}
/*打印输出*/
for (int i = 0; i < size; i++) {
System.out.println("从右到左第"+(i+1)+"位是: "+A[i]);
}
}
}