Java 为什么会出现语法错误
这是我的考试项目,当我运行程序时,似乎有语法错误。错误发生在第8行和第9行,即包含类的行和它下面的行。我在这里做的是菜单,这些是选项。我使用Ready to program来创建程序 您缺少的{: 编辑 正如@ccheneson所提到的,类定义的结尾}似乎也丢失了Java 为什么会出现语法错误,java,syntax-error,Java,Syntax Error,这是我的考试项目,当我运行程序时,似乎有语法错误。错误发生在第8行和第9行,即包含类的行和它下面的行。我在这里做的是菜单,这些是选项。我使用Ready to program来创建程序 您缺少的{: 编辑 正如@ccheneson所提到的,类定义的结尾}似乎也丢失了 您应该看看您的代码缩进,它在一开始看起来不错,但后来失败了。通过适当的缩进,您可以很容易地发现这些错误,因为几乎所有缩进的块都必须用{and}括起来。运行程序时出现语法错误-编译时出现语法错误,而不是运行程序。程序编译吗?如果没有,那
您应该看看您的代码缩进,它在一开始看起来不错,但后来失败了。通过适当的缩进,您可以很容易地发现这些错误,因为几乎所有缩进的块都必须用{and}括起来。运行程序时出现语法错误-编译时出现语法错误,而不是运行程序。程序编译吗?如果没有,那么编译器会给你什么错误信息?你看起来像是缺少{就在公共类求和之后。仅供将来参考,请尝试选择建议错误的行,例如,在本例中,第8行,因为你的问题不清楚第8行在哪里。
// The "Summative" class.
// Melanie Deivendram
// Jan.16,2012
// Purpose: To create a program as part of the summative
import java.awt.*;
import hsa.Console;
public class Summative
static Console c; // The output console
public static void main (String[] args)
{
c = new Console ();
// Title Page
c.setColor (Color.orange);
c.fillRect (0, 0, 2000, 900);
c.drawRect (0, 0, 2000, 900);
c.setColor (Color.white);
Font times = new Font ("Times", Font.BOLD, 50);
c.setFont(times);
c.drawString ("Summative", 180, 50);
Font tahoma = new Font ("Tahoma", Font.BOLD, 20);
c.setFont(tahoma);
c.getChar ();
c.clear ();
int choice;
{
c.drawString ("\t\t 1.Count Vowels", 0, 250);
c.drawString ("\t\t 2.One Dimensional Array Task", 0, 300);
c.drawString ("\t\t 3.Graphical animation", 0, 350);
c.drawString ("\t\t 4.String Methods", 0, 400);
c.drawString ("\t\t 5.ICS3U Program Portfolio ", 0, 450);
c.drawString ("\t\t 6.Exit", 0, 490);
}
do
{
c.print ("What is your choice (1-6): ");
choice = c.readInt ();
if ((choice < 1) || (choice > 6))
c.println ("Invalid ... enter 1-6 only");
}
while ((choice < 1) || (choice > 6));
switch (choice)
{
}
}
if (choice==1)
{
c.println ("What word would you like to enter?");
String word = c.readString ();
int count1 = 0;
for (int num = 0 ; num < word.length () ; num++)
{
char numbers = word.charAt (num);
if (numbers == '0' || numbers == '1' || numbers == '2' || numbers == '3' || numbers == '4' || numbers == '5' || numbers == '6' || numbers == '7' || numbers == '8' || numbers == '9')
{
count1++;
}
}
if (count1 != 0)
{
c.println("That is invalid, please try again");
}
if (count1 == 0)
{
int count = 0;
for (int num = 0 ; num < word.length () ; num++)
{
char vow = word.charAt (num);
if (vow == 'a' || vow == 'e' || vow == 'i' || vow == 'o' || vow == 'u' || vow == 'A' || vow == 'E' || vow == 'I' || vow == 'O' || vow == 'U')
{
count++;
}
}
c.println (" There are " + count + " vowels");
if (count == 0)
{
c.println("There are no vowels in the word");
}
}
public class Summative {
static Console c;