首先让我说我只是开始学习java,所以这可能(可能)是一个初学者的问题。 我得到一个指针返回而不是一个骰子滚动的数组。 3个类,Tienduizend,Roll和Player。
Tienduizend:
package tienduizend;
import java.util.Scanner;
public class Tienduizend {
public static void main(String[] args) {
Roll roll = new Roll(5);
Scanner Scan = new Scanner(System.in);
System.out.println("Speler 1 naam: ");
Player player1 = new Player(Scan.nextLine(), 0, 5);
System.out.println("Speler 2 naam: ");
Player player2 = new Player(Scan.nextLine(), 0, 5);
System.out.println(player1.getName() + " is aan zet:");
System.out.print(player1.getName() + " gooit: ");
System.out.print(roll.getRoll());
}
}
辊:
package tienduizend;
import java.util.Random;
public class Roll {
private int[] roll;
private int[] keep = new int[5];
private int toRoll;
public Roll(int rolls) {
roll = new int[rolls];
for (int i = 0; i < rolls; i++) {
roll[i] = rollDice();
}
}
public int rollDice() {
Random rand = new Random();
return rand.nextInt(6) + 1;
}
public int[] getRoll() {
return roll;
}
public int getTempScore(int[] a) {
return 100;
}
public int getFinalScore() {
return 1000;
}
}
播放器:
package tienduizend;
public class Player {
private int totalScore;
private String name;
private int toRoll;
public Player(String name, int totalScore, int toRoll) {
this.name = name;
this.totalScore = totalScore;
this.toRoll = toRoll;
}
public String getName() {
return name;
}
public int getTotalScore() {
return totalScore;
}
public void setTotalScore(int totalScore) {
this.totalScore = totalScore;
}
public int getToRoll() {
return toRoll;
}
public void setToRoll(int toRoll) {
this.toRoll = toRoll;
}
}
我的错误是怎么解决的? 提前谢谢!
简而言之; 主叫:
System.out.print(roll.getRoll());
给了我:
[I@1b6d3586
虽然它应该返回一组骰子卷。 (如1,2,3,4,5)