/*键盘输入数据,记录在数组内,然后打印输出,然后反转,再打印输出*/
import java.util.*;
class ArrayPrint {
public static void main(String[] args) {
System.out.println("请输入10个数字,存入数组:");
Scanner sc = new Scanner(System.in);
int []arr = new int[10];
for (int x=0;x<10 ;x++ ){//循环输入
int num = sc.nextInt();
arr[x] = num;
}
print(arr);
fanZhuan(arr);
System.out.println("\n--------------------------------");
print(arr);
System.out.println("\n请输入1个数字(1--11),我告诉你数组中对应位置的值:");
int num=sc.nextInt();
if (num>11||num<1){
System.out.println("输入1--11 !!!!!!!!");
}
char[] chs={'零','一','二','三','四','五','六','七','八','九','十'};
System.out.println("\n"+chs[num-1]);
int [][]ar={{1,2,3,4,5,6,76,7},{43,2,3,65,6,7},{978,456,34,2}};
erWei(ar);
}
public static void print(int []arr){//遍历打印
for (int x=0;x<arr.length ;x++ ){
System.out.print(arr[x]+" ");
}
}
public static void fanZhuan(int []arr){//数组反转
for (int i=0;i<arr.length/2 ;i++ ){
int temp = arr[i];
arr[i]=arr[arr.length-1-i];
arr[arr.length-1-i]=temp;
}
}
public static void erWei(int [][]ar){//二位数组遍历
for (int x=0;x<ar.length ;x++ ){
for (int y=0;y<ar[x].length ;y++ ){
System.out.print(ar[x][y]+" ");
}
System.out.println();
}
}
}
|
|