【问题标题】:figuring out where I am missing a } [closed]弄清楚我在哪里缺少 } [关闭]
【发布时间】:2012-11-08 02:45:36
【问题描述】:

当我编译时,我得到这个错误:解析时到达文件结尾}^ 我知道我错过了一个 } ,我在最后添加了一个但仍然得到相同的编译错误..我的眼睛看起来都在交叉 }...任何有一双清晰眼睛的人都可以指出明显的问题吗?

已解决...删除的代码

【问题讨论】:

  • 在切换结束时。默认值:中断; }
  • 使用为您执行此操作的编辑器! Eclipse、Netbeans、Emacs ......任你选!
  • 看起来您忘记关闭 switch(a) 之后的大括号{
  • 伙伴 - 如果您按照约定更好地缩进代码,您将能够更轻松地看到。

标签: java


【解决方案1】:

此代码的格式需要更好的一致性。使用IDE,您可以自行找到此类问题的解决方案。

【讨论】:

  • 为什么投反对票?教男人/女人怎么钓鱼,不要整天只分发鱼……这不是一半的问题cmets说的吗?
  • 在这里,我会用赞成票来平衡这一点。
【解决方案2】:

没有} 可以结束swtich

default:
          break;
}

                  c++;

     System.out.print( "\n\t\t\tEnter Another Pledge? (Y/N)?\n\t\t\t" );
     a = Keyboard.nextLine();

【讨论】:

    【解决方案3】:
    import java.util.Scanner;
    import java.text.*;
    
    public class test2
    {
      public static void main(String[] args)
      {
          final int Max = 50;
          int c = 0;
          int s = 0;
          int number =0;
          String a;
          char choice, summary;
          Student [] jogathon = new Student[Max];
          Scanner Keyboard = new Scanner(System.in);
    
            for (int i=0; i< Max; i++) {
            jogathon[i].laps = 0;
            jogathon[i].amount = 0;
            jogathon[i].totals = 0;
    
            } // make it more visible to relieve yoursel of this problem
    
          do
          { // next time put tabs after here
          Student.opening();
    
          System.out.print( "\n\t\tIs this a Donation? (y/n)?\n\t\t" );
              a = Keyboard.nextLine();
              choice = a.charAt(0);
    
                switch(a)
                { // what an ugly way to format a switch statement...
    
                case 'n':
              case 'N':
                  jogathon[c].getdata();
                  s = jogathon[c].number;
                  if (s >= 1 && s <= 7)
                  {
                      jogathon[c].gettotals();
                      jogathon[c].toString();
                      jogathon[c].showTotals();
    
                  }
    
                  break;
    
              case 'y':
              case 'Y':
                 jogathon[c].number = 0;
                 jogathon[c].gettotals();
                 jogathon[c].toString();
                 jogathon[c].showTotals();
    
                  break;
    
              default:
              break;
         } // look you forgot the } here at the end of the switch statement
                      c++;
         System.out.print( "\n\t\t\tEnter Another Pledge? (Y/N)?\n\t\t\t" );
         a = Keyboard.nextLine();
         choice = a.charAt(0);
         choice = Character.toUpperCase(choice);
          // this one below goes to the end of the "do{"
         } while (((a == 'Y') || (a == 'y')) && (c > Max));
    
    
           for (int i=0; i< c; i++) {
                 System.out.println(i + "\t" + jogathon[i].name + "\t" + >money.format(jogathon[i].pledge));
       }
    
           System.out.println( "===============================\n");
           for (int i=0; i< 7; i++) {
               System.out.println(jogathon[c].names[i] + "\t" + >  >money.format(jogathon[c].totals[i]));
           }
    // missing your final }'s here I think maybe you just omitted the rest
    

    【讨论】:

      猜你喜欢
      • 2019-09-10
      • 2021-06-27
      • 2022-06-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-31
      • 2011-10-26
      • 1970-01-01
      相关资源
      最近更新 更多