gpt4 book ai didi

java - 为什么这个 javaclass 会得到这个异常?

转载 作者:行者123 更新时间:2023-11-29 07:31:26 24 4
gpt4 key购买 nike

<分区>

我从网站上获取这段代码以适应其他用途,但当我在 Netbeans 上尝试时,它一直给我带来问题。我仔细看了看,它看起来很结实,但是,我显然不是……异常(exception)情况是:

"'{' Expected" and "class, interface, or enum expected."

我检查了所有的括号和大括号,但我无法弄清楚它有什么问题。

public class Coin() 
{
private String sideUp;

/**
* Default constructor
*/
public Coin()
{
// initialize sideUp
toss();
}

/**
* This method will simulate the tossing of a coin. It should set
* the
* sideUp field to either "heads" or "tails".
*/
public void toss()
{

Random rand = new Random();

// Get a random value, 0 or 1.
int value = rand.nextInt(2);

if (value == 0)
{
this.sideUp = "heads";
}
else
{
this.sideUp = "tails";
}
}

/**
*
* @return The side of the coin facing up.
*/
public String getSideUp()
{
return sideUp;
}
}

有没有我遗漏的支架?

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com