Java代码简单数学
问题描述:
我被困在下面的代码3的解决方案。我需要插入一个简单的数学问题,并且我不能在阅读我的书和课堂样本视频之后为生活找出这个问题。我希望程序能够提出这样的问题:“回答”64“的问题的答案是”8提高到2的权力“。任何人愿意帮助我?如果有人能让我开始,我可以想出另外两个问题。非常感谢你!!金Java代码简单数学
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
答
我需要一点信息才能给你答案。它看起来像代码想要一个随机数字生成器,但在你的问题中,你要求8^2或8 * 8。你想要哪一个?我问,因为随机数生成比硬编码数变量
答
当你运行你的程序有很大不同,在main
你有responseE
总是被设置为“定”。因为:
看看你的代码的流程:
double score = 0;
if (score <=85)
responseE = "Definite";
else if (score <=70)
...
...
第一if
总是不满意,所以它总是会被执行。
而且,即使你将评估responseE
你读的分数后,你需要重新考虑你如何编写条件..注意,如果然后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";
}
同为要评估后你读的输入等领域。
+1
简而言之,您在阅读score__之前根据分数确定回复 – 2013-03-11 18:21:17
谢谢大家的更正。新班对我来说,我不赶快赶上。 IrishWhiskey(随机数)我想?!假设提出问题并告诉用户答案是正确还是不正确......? – 2013-03-11 20:11:26