1
該程序將輸入4位玩家的分數,當您輸入分數時,應該顯示右邊的當前節目,就像這張圖片一樣。 因爲我沒有使用數據庫中的數據,我不能使用System.out.format二維數組的輸出總數
什麼是應該的樣子:
我有什麼,我認爲應該是它的邏輯,我只是不知道如何輸出,所以看起來和圖片一樣。 這是迄今爲止代碼:
private static final int NUMBER_OF_ENDS = 10;
private static String[] player = new String[4];
private static int[][] scores = new int[4][NUMBER_OF_ENDS];
private static int totalsOne = 0;
private static int totalsTwo = 0;
private static int totalsThree = 0;
private static int totalsFour = 0;
public static void addPlayer() {
//for loop to add player to player array
Scanner input = new Scanner(System.in);
for (int counter = 0; counter < player.length; counter++) {
System.out.println("Enter player #" + counter + " name");
player[counter] = input.nextLine();
}
}
public static void addScores() {
//for loops to add scores to particular end and show user current score
String output = "";
Scanner input = new Scanner(System.in);
for (int inner = 0; inner < NUMBER_OF_ENDS; inner++) {
for (int counter = 0; counter < player.length; counter++) {
System.out.print("Enter score number " + (inner + 1) + " score for " + player[counter] + "---->");
scores[counter][inner] = input.nextInt();
System.out.println("Current Scores-\n");
System.out.println(getResults(inner));
if (counter ==0){
totalsOne += scores[counter][inner];
}else if(counter ==1){
totalsTwo += scores [counter][inner];
}else if(counter ==2){
totalsThree += scores [counter][inner];
}else if(counter ==3){
totalsFour += scores [counter][inner];
}
}
}
}
private static String getResults(int currentEnd) {
//format current results
String result = "";
for (int count = 0; count < player.length; count++) {
result += player[count];
for (int i = 0; i <= currentEnd; i++) {
result += "\t" + scores[count][i];
}
result += "\n";
}
return result;
}
}
[輸出表的格式在Java的System.out的]的可能的複製(HTTP:/ /stackoverflow.com/questions/2745206/output-in-a-table-format-in-javas-system-out) –
不,不是。 –
你能告訴我們你的問題有什麼不同嗎? –