java第四次作业
作者:互联网
package nnn1;
import java.util.Arrays;
import java.util.Scanner;
public class nnn1 {
public static void main(String[] args) {
// TODO Auto-generated method stub
int xLen = 3;
int yLen = 3;
int[][] a = new int[xLen][yLen];
//使用随机数填充二维数组
for(int i=0;i<xLen;i++) {
for(int j=0;j<yLen;j++) {
a[i][j] = (int)(Math.random() * 100);
}
}
//复制二维数组到一维数组
int[] b = new int[xLen * yLen];
int k = 0;
for(int i=0;i<xLen;i++) {
for(int j=0;j<yLen;j++) {
b[k++] = a[i][j];
}
}
System.out.println("排序前:");
for(int i=0;i<xLen;i++) {
System.out.println(Arrays.toString(a[i]));
}
//调用Arrays中的sort方法
Arrays.sort(b);
//将排序后的值复制回二维数组
k = 0;
for(int i=0;i<xLen;i++) {
for(int j=0;j<yLen;j++) {
a[i][j] = b[k++];
}
}
System.out.println("排序后:");
for(int i=0;i<xLen;i++) {
System.out.println(Arrays.toString(a[i]));
}
}
}
import java.util.Scanner;
public class test10 {
public static void main(String[] args) {
System.out.println("您想调取第几位学生的答题结果(有效数字为1~8):");
Scanner sc=new Scanner(System.in);
int a=sc.nextInt();
System.out.print("第"+a+"位同学的全部答案为:");
int sum=0;
char score[][]=new char[8][10];
char arr[]=new char[]{'B','A','D','C','C','B','C','A','D','B'};
score[0]=new char[]{'A','B','C','D','A','C','B','D','A','D'};
score[1]=new char[]{'B','A','D','B','A','B','B','A','C','B'};
score[2]=new char[]{'B','A','D','B','A','B','C','A','C','B'};
score[3]=new char[]{'A','B','C','D','A','C','B','D','A','D'};
score[4]=new char[]{'A','B','C','D','A','C','B','D','A','D'};
score[5]=new char[]{'A','B','C','D','A','C','B','D','A','D'};
score[6]=new char[]{'A','B','C','D','A','C','B','D','A','D'};
score[7]=new char[]{'A','B','C','D','A','C','B','D','A','D'};
System.out.print(score[a]);
for (int i = 0; i < 10; i++)
{
if (arr[i] == score[2][i]){
sum++;
}
//B A D BA B C A C B
//B B C D A C B D A D
}
System.out.println();
System.out.println("第"+a+"位同学一共答对了"+sum+"道题");
}
}
标签:java,int,作业,System,char,score,new,out,第四次 来源: https://blog.csdn.net/m0_64535103/article/details/123603715