即時通訊嘗試完成我的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