- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
由于某种原因,我收到一个语法错误,提示“语法错误,插入“}”以完成 ClassBody。”我检查了每个方法、每个语句,以确保我有完整的左括号和右括号,所以我不知道为什么会发生这种情况。谁能告诉我为什么我会遇到这个问题?
将代码复制到另一个文件中并不能解决问题,转到“项目”>“清理”也不能解决问题。
import java.util.Scanner;
public class jloneman_Numerology
{
private String[] report;
private int day, month, year, num;
public jloneman_Numerology()
{
introduction();
report = new String[9];
num = 0;
}
public void introduction()
{
System.out.println("Welcome to ACME Numerology Reports! We will " +
"determine your special\nnumerology report based on your " +
"birth date.\n");
}
public void getDate()
{
char slash1, slash2;
do
{
System.out.print("Please enter your birth date (mm / dd / yyyy): ");
Scanner in = new Scanner(System.in);
String date = in.nextLine();
month = in.nextInt();
day = in.nextInt();
year = in.nextInt();
slash1 = date.charAt(3);
slash2 = date.charAt(8);
} while (validDate(slash1, slash2) == false);
calcNum();
}
public boolean validDate(char slash1, char slash2)
{
boolean isValid = true;
// Check for valid month
if (month < 1 || month > 12)
{
isValid = false;
System.out.printf("Invalid month: %d\n", month);
}
// Check for valid day
if (day < 1 || day > 31)
{
isValid = false;
System.out.printf("Invalid day: %d\n", day);
}
// Check for months with 30 days, else 31 days = invalid
if ((month == 4 || month == 6 || month == 9 || month == 11) && (day < 1 || day > 30))
{
isValid = false;
System.out.printf("Invalid day: %d\n", day);
}
else if (day < 1 || day > 31)
{
isValid = false;
System.out.printf("Invalid day: %d\n", day);
}
// Check for valid year
if (year < 1880 || year > 2280)
{
isValid = false;
System.out.println("Please enter a valid year between 1880 and 2280.");
}
// Check for correct separating character
if (slash1 != '/' || slash2 != '/')
{
isValid = false;
System.out.println("Invalid separating character, please use forward slashes");
}
if (leapYear() == true)
{
if (month == 2 && day > 29)
{
isValid = false;
System.out.printf("Invalid day for 2/%d: %d", year, day);
}
}
return isValid;
}
public boolean leapYear()
{
boolean isLeap;
if (year % 4 == 0 && year % 400 != 0)
isLeap = false;
else
isLeap = true;
return isLeap;
}
public void calcNum()
{
// Separate each digit of the date and add to a single number
// Test number for debugging
num = 5;
}
public void printReport()
{
report[0] = ":1: ";
report[1] = ":2: ";
report[2] = ":3: ";
report[3] = ":4: ";
report[4] = ":5: ";
report[5] = ":6: ";
report[6] = ":7: ";
report[7] = ":8: ";
report[8] = ":9: ";
System.out.println(report[num]);
}
}
78,0-1 Bot
最佳答案
尝试删除(或注释掉)一种方法,看看问题是否仍然存在。如果是这样,请删除或注释掉其他方法,依此类推,直到错误消失。然后恢复除最后一个方法之外的所有内容。
如果错误不再出现,则问题可能出在最后一个方法中。
如果它确实再次出现,则问题更加微妙;也许是嵌入在代码中的控制字符。尝试将代码复制并粘贴到纯文本编辑器中(这样任何控制字符都将被忽略,保存并重新编译。
关于java - 语法错误,插入 "}"来完成 ClassBody?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13774350/
很难说出这里问的是什么。这个问题是含糊的、模糊的、不完整的、过于宽泛的或修辞性的,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开它,visit the help center 。 已关
我环顾四周,似乎找不到解决方案。我不确定我的代码有什么问题。链接到我的代码 http://pastebin.com/8z7rjVVK 编译时收到错误: ===== COMPILING - PL
已关闭。这个问题是 not reproducible or was caused by typos 。目前不接受答案。 这个问题是由拼写错误或无法再重现的问题引起的。虽然类似的问题可能是 on-top
我创建了一个方法并不断收到一个错误,我需要在我的方法末尾包含一个 }。我把 } 放进去,错误仍然存在!如果我然后删除那个 } 相同的错误将在先前的方法中弹出;之前没有那个错误。换句话说,如果我在我
已关闭。这个问题是 not reproducible or was caused by typos 。目前不接受答案。 这个问题是由拼写错误或无法再重现的问题引起的。虽然类似的问题可能是 on-top
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 要求提供代码的问题必须表现出对所解决问题的最低限度理解。包括尝试过的解决方案、为什么它们不起作用,以及预
是的。我知道这是微不足道的。但这越来越愚蠢了。 证明错误的图片: 代码: package apack.age; import android.app.Activity; import android.
我正在开发一个 Android 应用程序,它在队列中使用了 sereval 库。这意味着: 项目 A 是图书馆。 项目 B 使用图书馆 A 并且是图书馆。 项目 C 用户图书馆 B。 现在在项目 A
这个问题已经有答案了: syntax error: insert } to complete ClassBody (12 个回答) 已关闭 6 年前。 我遇到错误“语法错误,插入“}”以完成 Clas
我收到两条错误消息 1. 标记“;”上的语法错误,{ 在此标记后应有的内容;2. 语法错误,插入“}”以完成 ClassBody。这段代码有什么问题? public class AAExample {
我刚刚在 Eclipse 中创建了一个新项目,R.java 在最后一个分号上显示“语法错误,插入“}”以完成 ClassBody”。 我仔细检查了我所有的 XML 文件是否有错误、失误、拼写错误和空参
我是一名优秀的程序员,十分优秀!