为什么会出现语法错误

时间:2013-01-23 10:57:21

标签: java syntax-error

// 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");
      }

  } 

这是我的考试项目,运行程序时似乎出现语法错误。错误发生在第8行和第9行,其中包含类和下面的类。我在这里做的是一个菜单,这些是选项。我使用“准备编程”来创建程序。

2 个答案:

答案 0 :(得分:3)

您遗失的{

public class Summative {

    static Console c;

修改

如@ccheneson所述,您的班级定义的结束}似乎也不见了。

你应该看看你的代码缩进,它在开始时似乎很好,但是稍后会失败。通过适当的缩进,您可以轻松发现这些错误,因为几乎任何缩进块都必须被{}括起来。

答案 1 :(得分:0)

您错过了class Summative的开括号和近距离括号。这就是为什么,你的IDE也没有强调没有这个括号。