構建一個可幫助用戶練習添加的Java程序。使用添加方法,我添加了我的代碼,如下所示。這是給我布爾錯誤。此外,它會在用戶輸入名稱後運行,然後出現錯誤。Java - 方法和最終變量
UPDATED
錯誤命令提示符:
CAI.java:46: error: missing return statement
}
^
1 error
CAI.java
import java.util.Scanner;
import java.util.Random;
public class CAI
{
static Scanner input = new Scanner(System.in);
static int addition;
//main method
public static void main(String[] arguments)
{
//declare variables
String name;
int addition;
int subtraction;
int multiplication;
boolean = true;
//welcome the user
System.out.println("Welcome to Computer Assisted Instruction");
//get the user's name
System.out.print("Enter your name: ");
name = input.next();
System.out.printf("Hi %s. Let's practice addition!", name);
}
private static boolean addition()
{
//generate double digit numbers positive and negative
int number = 0;
//Addition
System.out.printf("What is %d + %d? ", number);
addition = input.nextInt();
}
}
'CAI.java:43:錯誤:找不到符號 addition = input.next(); ^ 符號:變量加法 位置:類CAI 1錯誤' –
檢查第4和第5點@TevelZaki –
'CAI。Java的:46:錯誤:缺少return語句 } ^ 1 error' –