这是我根据运动创建的一个测验,它提出了一系列问题,用户每次尝试 3 次。从那里它汇总每个玩家的分数并以二维数组的形式显示,它比较分数并打印最高分数。我将如何使用冒泡排序(不是 array.sort)按第二个索引(分数)对二维数组(记分板)进行排序。
import java.util.*;
class miniproj
{
public static void main(String[] args)
{
Questions[] questions = setQuestions(); // store array of questions using setquestions method
askQuestion(questions); // run method askquestion using questions parameter (array)
}
public static Questions[] setQuestions()
{
Questions[] questions = new Questions[4]; //create array of type questions
Questions A = new Questions(); // create new questons type called A
A.question = "What team won the world cup in 1966?";
A.options = " A. Germany\n B. France\n C. England\n D. Wales";
A.answer = "C";
questions[0] = A; // the first question in the aray is A
Questions B = new Questions();
B.question = "Who are the current EPL title holders?";
B.options = " A. Arsenal\n B. Bournemouth\n C. Chelsea\n D. Manchester City";
B.answer = "D";
questions[1] = B;
Questions C = new Questions();
C.question = "Who is the current Golden Boot holder 2017/18 season?";
C.options = " A. Lionel Messi\n B. Harry Kane\n C. Cristiano Ronaldo\n D. Davidson Sanchez";
C.answer = "A";
questions[2] = C;
Questions D = new Questions();
D.question = "Which team has most goals";
D.options = " A. Arsenal\n B. Bournemouth\n C. Chelsea\n D. Manchester City";
D.answer = "A";
questions[3] = D;
return questions; // return array of questions
}
public static void askQuestion(Questions[] array)
{
int correct = 0;
Scanner sc = new Scanner(System.in);
String[][] scoreboard = new String[4][2];
for(int m = 0; m < scoreboard.length; m++) {
correct = 0;
System.out.println("What is your name");
scoreboard[m][0] = sc.nextLine();
翻阅古今
白板的微信
相关分类