一、交换二维数组

public class 交换二维数组 {
public static void main (String args []) {
int array [][] = new int [3][3] ;
array [0] = new int [] {91,25,8};
array [1] = new int [] {56,14,2};
array [2] = new int [] {47,3,67};
System.out.println("-----原始数组-----");
for (int i = 0;i <= 2; i++) {
for (int j = 0;j <= 2; j++) {
System.out.print(array[i][j]);
System.out.print(" ");
if (j == 2)
System.out.println();
}
}
System.out.println("--调换位置之后的数组--");
for (int j = 0;j <= 2; j++) {
for (int i = 0;i <= 2; i++) {
System.out.print(array[i][j]);
System.out.print(" ");
if (i == 2)
System.out.println();
}
}
}
}
运行结果:

二、查询成绩

import java.util.Scanner;
public class 查询成绩 {
public static void main (String args []) {
System.out.println("您想调取第几位学生的答题结果1(有效数字为1至8):");
Scanner sc = new Scanner (System.in);
int n = sc.nextInt();
System.out.println("第"+ n +"位同学的全部答案为:");
int sum = 0;
char answer [][] = new char[8][10];
char arr [] = new char [] {'B','A','D','C','C','B','C','A','D','B'};
answer[0] = new char [] {'A','B','C','B','A','D','C','D','A','C'};
answer[1] = new char [] {'B','A','D','B','A','B','C','A','C','B'};
answer[2] = new char [] {'A','B','C','B','A','D','C','D','A','D'};
answer[3] = new char [] {'A','B','C','C','A','D','D','B','A','C'};
answer[4] = new char [] {'B','B','C','B','C','B','C','D','A','C'};
answer[5] = new char [] {'A','B','C','A','A','C','C','D','A','C'};
answer[6] = new char [] {'B','B','A','B','D','D','C','D','A','C'};
answer[7] = new char [] {'A','B','D','D','A','D','C','D','A','C'};
System.out.print(answer [n-1]);
for (int i = 0; i < 10; i++) {
if (arr[i] == answer[n-1][i]) {
sum++;
}
}
System.out.println();
System.out.println("第"+ n +"位同学一共答对了"+ sum +"道题");
}
}
运行结果:

148

被折叠的 条评论
为什么被折叠?



