-3

Is there a way to write switch statement in java without having to always rewrite multiple case? As you can see in the picture. can i just remove all the cases for one instance and just use one case and still have the variables ex. case: 1,2,3,4:

Will that work in java using switch statement? java switch statement

  • Possible duplicate of [In Java,Using switch statement with a range of value in each case?](http://stackoverflow.com/questions/10873590/in-java-using-switch-statement-with-a-range-of-value-in-each-case) – sstan Oct 16 '16 at 05:04
  • Also, please don't use images in questions. Copy paste the code as text (with proper formatting of course). – sstan Oct 16 '16 at 05:11
  • Please put the code in the actual question. – Dawood ibn Kareem Oct 16 '16 at 05:25

2 Answers2

1

No, there isn't. You need to always start every choice by case <choice-value>:

The only thing you can raise the density is to put the cases on single line as Java is free about format. Note it's questionable whether in different cases it improves the readability or the opposite:

switch (value) {
case 1: case 2: case 3:
       doSomething ();
       break;
 ....
}
Zbynek Vyskovsky - kvr000
  • 18,186
  • 3
  • 35
  • 43
-1

nope. unfortunately there no such syntax supported in java.

vatsal mevada
  • 5,148
  • 7
  • 39
  • 68