Java 我如何修复我的";“类型”的非法启动;及&书信电报;标识符>;“预期”;我的返回语句有错误吗?

Java 我如何修复我的";“类型”的非法启动;及&书信电报;标识符>;“预期”;我的返回语句有错误吗?,java,return,expression,identifier,Java,Return,Expression,Identifier,我知道这与我的括号位置有关,但我不确定错误发生在哪里。请记住,这是我班上的第二种方法 import java.util.Scanner*; import java.util.Arrays.*; public class BasicMathTest { //Creates an array to store the numbers that will be used in the math problems int alpha[] = {4, 8, 10, 15, 25, 30}; int be

我知道这与我的括号位置有关,但我不确定错误发生在哪里。请记住,这是我班上的第二种方法

import java.util.Scanner*;
import java.util.Arrays.*;
public class BasicMathTest
{
//Creates an array to store the numbers that will be used in the math 
problems
int alpha[] = {4, 8, 10, 15, 25, 30};
int beta[] = {2, 4, 5, 3, 5, 10};
double Problems = alpha.length;
public static void main(String args[])
{
    System.out.println("Welcome to this Math Quiz. Here you will add, subtract, multiply and divide!");

    //Ask the user to choose their type of problem
    Scanner kbReader = new Scanner(System.in);
    System.out.println("Select Addition (1), Subtraction (2), Multiplication (3) or Division (4): ");
    int Selection = kbReader.nextInt();
    
    //Calculates the users score
    double score = Selection * 100 / Problems;
    System.out.println("Your score on the test: " + score + "%");
}
    
public static double Selection ()
{
    int score = 0; //Stores the number of correct answers
    int correct; //Stores the correct answer
    for (int i = 0; i < Problems; i++)
    {
        if (Selection == 1)
        {
            System.out.println(alpha[i] + " + " + beta[i]);
            correct = alpha[i] + beta[i];
        }
        else if(Selection == 2)
        {
            System.out.print(alpha[i] + " - " + beta[i]);
            correct = alpha[i] - beta[i];
        }
        else if (Selection = 3)
        {
            System.out.print(alpha[i] + " * " + beta[i]);
            correct = alpha[i] * beta[i];   
        }
        else if(Selection == 4)
        {
            System.out.print(alpha[i] + " / " + beta[i]);
            correct = alpha[i] / beta[i];
        }
    }
    System.out.println(" ");
}
return score;
}
导入java.util.Scanner*; 导入java.util.Arrays.*; 公共类BasicMathTest { //创建一个数组来存储将在数学运算中使用的数字 问题 int alpha[]={4,8,10,15,25,30}; int beta[]={2,4,5,3,5,10}; 双重问题=α长度; 公共静态void main(字符串参数[]) { System.out.println(“欢迎参加这个数学测验。在这里你将做加法、减法、乘法和除法!”); //请用户选择他们的问题类型 扫描仪kbReader=新扫描仪(System.in); System.out.println(“选择加法(1)、减法(2)、乘法(3)或除法(4):”; int Selection=kbReader.nextInt(); //计算用户得分 双倍分数=选择*100/问题; System.out.println(“您在测试中的分数:+分数+”%); } 公共静态双重选择() { int score=0;//存储正确答案的数量 int correct;//存储正确答案 for(int i=0;i
Output:E:\Xinox Software\JCreatorV4LE\MyProjects\CreateTask\BasicMathTest.java:52:类型的非法启动
返回分数;
^
E:\Xinox Software\JCreatorV4LE\MyProjects\CreateTask\BasicMathTest.java:52:预期值
返回分数;
^
2个错误
问题:

  • 如果您忘记了在“Selection==4”处用大括号括起来
  • 在“中写入“==”而不是“中的**“=”,如果(选择=3)
  • 分数类型为双倍
您能告诉我们您如何使用分数var吗

看看这个,让我知道它是否正确:

public static double Selection ()
{
    double score = 0; //change from int to double
    int correct; //Stores the correct answer
    for (int i = 0; i < Problems; i++)
    {
        if (Selection == 1)
        {
            System.out.println(alpha[i] + " + " + beta[i]);
            correct = alpha[i] + beta[i];
        }
        else if(Selection == 2)
        {
            System.out.print(alpha[i] + " - " + beta[i]);
            correct = alpha[i] - beta[i];
        }
        else if (Selection == 3)
        {
            System.out.print(alpha[i] + " * " + beta[i]);
            correct = alpha[i] * beta[i];   
        }
        else if(Selection == 4) 
        { // missing brace
            System.out.print(alpha[i] + " / " + beta[i]);
            correct = alpha[i] / beta[i];
   
        }
        
        System.out.println(" ");
    }
    
    return score;
}
公共静态双重选择()
{
double score=0;//从int改为double
int correct;//存储正确答案
for(int i=0;i
First problem==您忘记了选项==4处的大括号。我添加了大括号,但错误仍然存在。您可以编辑并向我们显示一些预期结果和错误堆栈跟踪吗?如果(选项==3),也可以使用else,如果(选项==3)确定我发布了我的全部代码,并修复了选项3
public static double Selection ()
{
    double score = 0; //change from int to double
    int correct; //Stores the correct answer
    for (int i = 0; i < Problems; i++)
    {
        if (Selection == 1)
        {
            System.out.println(alpha[i] + " + " + beta[i]);
            correct = alpha[i] + beta[i];
        }
        else if(Selection == 2)
        {
            System.out.print(alpha[i] + " - " + beta[i]);
            correct = alpha[i] - beta[i];
        }
        else if (Selection == 3)
        {
            System.out.print(alpha[i] + " * " + beta[i]);
            correct = alpha[i] * beta[i];   
        }
        else if(Selection == 4) 
        { // missing brace
            System.out.print(alpha[i] + " / " + beta[i]);
            correct = alpha[i] / beta[i];
   
        }
        
        System.out.println(" ");
    }
    
    return score;
}