Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/397.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java代码简单数学_Java_Math - Fatal编程技术网

Java代码简单数学

Java代码简单数学,java,math,Java,Math,我被下面代码3的解决方案卡住了。我需要插入一道简单的数学题,但在阅读了我的书和课堂上的视频样本后,我一辈子都无法解决这个问题。我想让这个程序问一个问题,“8的幂为2的答案是什么”,答案是“64”。有人愿意帮我吗?如果有人能让我开始,我可以提出另外两个问题!非常感谢你!!金姆 import java.util.Scanner; //allows for input public class ASG03 { public static void main(String[] args)

我被下面代码3的解决方案卡住了。我需要插入一道简单的数学题,但在阅读了我的书和课堂上的视频样本后,我一辈子都无法解决这个问题。我想让这个程序问一个问题,“8的幂为2的答案是什么”,答案是“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
import java.util.Scanner//允许输入
公共类ASG03{
公共静态void main(字符串[]args){
扫描仪输入=新扫描仪(System.in);//允许输入
//步骤1-声明和初始化变量
字符串candidateName=“”;
字符串响应=”;
int选项=0;
双倍得分=0;

如果(分数在我给你答案之前,我需要更多的信息。看起来代码需要一个随机数生成器,但是在你的问题中,你要求的是8^2或8*8。你想要哪一个?我问这个问题是因为当你运行程序时,在
主程序中,随机数生成与硬编码数字变量有很大不同您将使
响应者
始终设置为“确定”。因为:

查看代码的流程:

double score = 0;
if (score <=85)
  responseE = "Definite";
else if (score <=70)
...
...
下面是方法
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";
}
私有静态字符串getResponse(双倍分数){
如果(得分70)
返回“确定”;
否则如果(得分60)
返回“可能”;
else if(得分40)//例如。。
返回“可能”;
返回“否”;
}

阅读输入后,您要评估的其他字段也一样。简而言之,您在阅读分数之前根据分数确定响应。谢谢大家的更正。为我开设了新课程,我不会很快理解。爱尔兰威士忌(随机数)我想?!它应该问问题并告诉用户答案是正确的还是错误的。。。?
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";
}