即时通讯尝试完成我的if语句,并且我无法将winChance解析为if语句中的变量,如果有人能够向我展示它,将不胜感激。该ereor是'目标之前会破产是:“+永昌);‘我的最后永昌方法没有返回一个双变量’解决if语句的变量
import java.util.Scanner;
public class StockiColeA1Q3 {
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in); //scanner
System.out.println("What is your first name? ");
String first = keyboard.nextLine();
System.out.println("What is your last name? ");
String last = keyboard.nextLine();
System.out.println("What is the amount of chips you are starting with, " + first +"?");
int start = keyboard.nextInt();
System.out.println("What is the amount of chips you wish you have ?");
int end = keyboard. nextInt();
System.out.println("What is the probability of each round? \n" +
"(A value between 0.0 and 1.0)");
double p = keyboard.nextDouble();
printResult(start,end,p,first,last);
}//main
public static void printResult(int start, int end, double p, String first, String last) {
System.out.println(first + " " + last +": If you start with " + start + " chips\n" +
"And do not quit until you have " + end + " chips,\n" +
"with the probability of " + p + " of winning each round, \n" +
"the chance of reaching your goal before going broke is: " + winChance);
}//print results
public static double winChance(double start, double end, double p) {
if (p==0.5) {
System.out.println(start/end);
}
else if (p>0&&p<1) {
System.out.println(1-(Math.pow((1-p)/p, start))/1-(Math.pow((1-p)/p, end)));
}//if p isnt 0.5
}//win chance
}//gamblers ruin
你实际上并没有声明一个叫做winChance的变量 – SamTebbs33 2014-10-02 17:42:31