English 中文(简体)
关于中断案件
原标题:Regarding putting break with an case
  • 时间:2012-04-29 06:41:43
  •  标签:
  • java

我正在通过一份有条件的换文守则。

char c1=65;
switch(c1){
  case  A :
    System.out.println("one");
  default:
    System.out.println("two");
  case  b :
    System.out.println("three");
}

虽然结果是两例,但我在总结时发现,它首先进入A案,ASCII值是A65,但随后它又执行所有剩余案件,但如果我停止审理;那么,如果我们不停,它将继续执行所有案件,请通知。

最佳回答

It will continue to execute it until reaches break. Here you can read more info about switch Statement.

问题回答

if you don t put break, all the rest cases after the matched case will be executed automatically. Control will come out of switch case in two cases:

1. When it ends.
2. When it finds a break.

页: 1 它明确界定了开关车是如何执行的。

成就

Switch。 因此,完成开关声明的执行。

不仅 Java 在许多语文中也是如此。

@user1351820, your understanding is correct.

Each break statement terminates the enclosing switch statement. Control flow continues with the first statement following the switch block. The break statements are necessary because without them, statements in switch blocks fall through: All statements after the matching case label are executed in sequence, regardless of the expression of subsequent case labels, until a break statement is encountered.

The program SwitchDemoFallThrough shows statements in a switch block that fall through. The program displays the month corresponding to the integer month and the months that follow in the year.

Technically, the final break is not required because flow falls out of the switch statement. Using a break is recommended so that modifying the code is easier and less error prone. The default section handles all values that are not explicitly handled by one of the case sections.
Ref: docs.oracle

Yes, all then remaing cases below the maching case will execute.
If your matching case is last then only the matching case will excute or matching case is in middle cases above the matching case will not execute, but cases below matching case will execute along with matching case.

char c1=65; switch(c1)
{
   case  B :
      System.out.println("three");

   default:
      System.out.println("two");

   case  A :
      System.out.println("one");  
} 

在这种情况下,你的产出为<代码>one。

是的,case statements起步。 如果你对背景原因感兴趣,这一结构源自C,C也称为“宏观组合”,即它是一种非常低的语言。 C中定义的<代码>switch说明对于最佳实施是完美的,因为在转换价值方面有一些限制,只需要两项指示:一项是关于跳跃的地址的表征,一项是跳跃。 在死灰复燃之后,没有进一步的干预——因此,需要一个明确的<条码>><>条/条码>,才能从条块中删除。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签