Visitador: added switchStmt with breaks
This commit is contained in:
parent
fcdab2da3f
commit
137d01938c
4 changed files with 125 additions and 1 deletions
28
src/test/res/mytest/BasicSwitch.java
Normal file
28
src/test/res/mytest/BasicSwitch.java
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
package mytest;
|
||||
|
||||
public class BasicSwitch {
|
||||
public static void main(String[] args) {
|
||||
int x = Integer.valueOf(args[0]);
|
||||
int y = -1;
|
||||
switch (x) {
|
||||
case 1:
|
||||
y = 10;
|
||||
break;
|
||||
case 2:
|
||||
y = 20;
|
||||
break;
|
||||
case 3:
|
||||
y = 30;
|
||||
break;
|
||||
case 4:
|
||||
case 5:
|
||||
y = 100;
|
||||
break;
|
||||
case 6:
|
||||
System.err.println("Error");
|
||||
case 10:
|
||||
y = 0;
|
||||
}
|
||||
System.out.println(y);
|
||||
}
|
||||
}
|
||||
23
src/test/res/mytest/BasicSwitchDefault.java
Normal file
23
src/test/res/mytest/BasicSwitchDefault.java
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
package mytest;
|
||||
|
||||
public class BasicSwitchDefault {
|
||||
public static void main(String[] args) {
|
||||
int x = Integer.valueOf(args[0]);
|
||||
int y;
|
||||
switch (x % 3) {
|
||||
case 0:
|
||||
y = 10;
|
||||
break;
|
||||
case 1:
|
||||
y = 20;
|
||||
break;
|
||||
case 2:
|
||||
y = 30;
|
||||
break;
|
||||
default:
|
||||
y = -1;
|
||||
break;
|
||||
}
|
||||
System.out.println(y);
|
||||
}
|
||||
}
|
||||
16
src/test/res/mytest/BasicSwitchNoBreak.java
Normal file
16
src/test/res/mytest/BasicSwitchNoBreak.java
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
package mytest;
|
||||
|
||||
public class BasicSwitchNoBreak {
|
||||
public static void main(String[] args) {
|
||||
String res = "";
|
||||
switch (args[0]) {
|
||||
case "a":
|
||||
res = "abc";
|
||||
case "b":
|
||||
res = "bac";
|
||||
case "c":
|
||||
res = "cab";
|
||||
}
|
||||
System.out.println(res);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue