在Java中切换声明属性?

时间:2018-02-28 04:44:04

标签: java c# switch-statement goto fall-through

我可以使用

吗?
  

转到转发

在Java中的 Switch语句中就像在C#中一样?

以下是我在C#中修改的代码示例,以便在条件交换机中使用 goto 语句,注意SAM所在的位置:

      // add 1 to appropriate counter for specified grade
       private void IncrementLetterGradeCounter( int grade )
       {
          // determine which grade was entered
          switch ( grade / 10 )
          {
             case 9: // grade was in the 90s
             case 10: // grade was 100 
                ++aCount; // increment aCount
                    goto case 8; // SAM: in this case I omitted the break 
                //by commenting and use the "goto case <number>;" 
                //which let me continue without errors
                //break; // necessary to exit switch
             case 8: // grade was between 80 and 89
                ++bCount; // increment bCount    
                break; // exit switch
             case 7: // grade was between 70 and 79
                ++cCount; // increment cCount    
                break; // exit switch
             case 6: // grade was between 60 and 69
                ++dCount; // increment dCount    
                break; // exit switch
             default: // grade was less than 60
                ++fCount; // increment fCount       
                break; // exit switch
          } // end switch
       } // end method IncrementLetterGradeCounter

1 个答案:

答案 0 :(得分:0)

goto未在Java中使用,尽管Keywords列表确实有goto条目,但未使用它。相反,您可以使用breakcontinue

相关问题