public class slots
{
public static void main(String[]args)
{
public String pull() {
int rand = (int)(Math.random()*3+1);
if(rand == 1)
return "cherries";
else if(rand == 2)
return "bar";
else
return "7";
}
string1 = pull();
string2 = pull();
string3 = pull();
}
}
class TripleString
{
public static final int MAX_LEN = 20;
private String string1;
private String string2;
private String string3;
TripleString()
{
string1 ="";
string2 ="";
string3 ="";
}
public void setTripleString (String str1, String str2, String str3)
{
string1 = str1;
string2 = str2;
string3 = str3;
}
public String getstring1()
{
return string1;
}
public String getstring2()
{
return string2;
}
public String getstring3()
{
return string3;
}
private boolean vaildString( String str )
{
if (str.length() >0 && str.length() <= MAX_LEN)
{
return true;
}
else
{
return false;
}
}
}
我目前有此代码,并正在尝试创建一个随机返回这些值的老虎机,但字符串 pull() 上存在语法错误,我不确定如何修复。有谁知道如何使这项工作?