[英]Java Code Simple Math
我堅持下面的代碼3的解決方案。 我需要插入一個簡單的數學問題,在翻閱我的書並從課堂上觀看視頻之后我無法想到這一點。 我希望程序能夠提出這樣一個問題:“8的強大之處是什么?”答案為“64”。 有誰願意幫幫我嗎? 如果有人能讓我開始,我可以提出另外兩個問題! 非常感謝你!! 金
import java.util.Scanner; //allows for input
public class ASG03 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in); //allows for input
//Step 1 - Declare and initialize variables
String candidateName = "";
String responseE = "";
int option = 0;
double score = 0;
if (score <=85)
responseE = "Definite";
else if (score <=70)
responseE = "Likely";
else if (score <=60)
responseE = "Maybe";
else
responseE = "No";
String responseI = "";
if (score <=85)
responseI = "Yes";
else if (score <=70)
responseI = "Yes";
else if (score <=60)
responseI = "Yes";
else
responseI = "No";
//Step 2 - Process input
System.out.println("Enter candidate name: ");
candidateName = input.nextLine();
System.out.println("Enter score 0 -100: ");
score = input.nextDouble();
System.out.println();
System.out.println("Enter 1 to set employment category ");
System.out.println("Enter 2 to set interview possibility ");
System.out.println("Enter 3 to view a sample test question ");
System.out.println("Enter option now -> ");
option = input.nextInt();
//Step 3 and 4 - Process calculations and output
switch(option)
{
case 1:
System.out.println("You are now setting the employment category...");
//can use nested if else
System.out.println("Employment category = " + responseE);
break;
case 2:
System.out.println("You are now setting the interview possibilities...");
System.out.println("Interview possibilites = " + responseI);
break;
case 3:
System.out.println("You are now viewing a sample test question...");
//use random and power from Math library
default:
}//end of switch
}//end of main
}//end of class
當您運行程序時,在main
您將始終將responseE
設置為“Definite” 。 因為:
查看代碼流:
double score = 0;
if (score <=85)
responseE = "Definite";
else if (score <=70)
...
...
第一個if
總是滿足,所以它總是被執行。
此外,即使您在閱讀得分后評估responseE
score <= 85
,您還需要再次考慮如何編寫條件。請注意,如果score <= 85
則score <= 70
....
你應該有這樣的東西:
在切換之前:
responseE = getResponse(score);
這是方法getResponse
:
private static String getResponse(double score) {
if (score <=85 && score >70)
return "Definite";
else if (score <=70 && score > 60)
return "Likely";
else if (score <=60 && score > 40) //For example..
return "Maybe";
return "No";
}
讀取輸入后要評估的其他字段也是如此。
在我給你答案之前,我需要更多的信息。 看起來代碼想要一個隨機數生成器,但是在你的問題中你要求8 ^ 2或8 * 8。 你想要哪個? 我問,因為隨機數生成與硬編碼數變量有很大不同
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.