public class Test public static void mainString! argsint a = 0whilea = 20switch acase 0case 1 a = a + 2case 2case 3 a = a + 3; breakdefault a = a + 5;Systemoutprinta= + a;
There are several syntax errors in your code. Here is the corrected version:
public class Test {
public static void main(String[] args) {
int a = 0;
while(a <= 20) {
switch (a) {
case 0:
case 1:
a = a + 2;
break;
case 2:
case 3:
a = a + 3;
break;
default:
a = a + 5;
}
System.out.println("a=" + a);
}
}
}
Here are the changes I made:
- Added closing parentheses for the class declaration and the main method declaration.
- Replaced the exclamation mark (!) with an array brackets ([]) in the main method declaration.
- Added opening and closing curly braces ({}) for the while loop and the switch statement.
- Added break statements after each case in the switch statement.
- Replaced "System,out.print" with "System.out.println" to print the output on a new line
原文地址: https://www.cveoy.top/t/topic/hBD5 著作权归作者所有。请勿转载和采集!