Correct the error in the following code : there is more than 1 error :
1-
importjava.util.Scanner; // import Scanner class publicclass We {
publicstaticvoid main(String[] args) {
Scanner input = newScanner(System.in);// create Scanner object System.out.println("number:");
intg= input.nextInt(); // Declare and read
switch(g==);
case1 :System.out.println("case1"); break;
case2 :System.out.println("case2"); break;
default :System.out.println("default"); }
}
2-
charg= 'a'; switch(g)
{
Case r :System.out.println("case1");
break;
case u: System.out.println("case2"); break;
default :System.out.println("default"); }
1 Answer
import java.util.Scanner;
public class App {
/**
* The start point of the program
*
* @param args
*/
public static void main(String[] args) {
Scanner input = new Scanner(System.in);// create Scanner object
System.out.println("number:");
int g = input.nextInt(); // Declare and read
switch (g) {
case 1:
System.out.println("case1");
break;
case 2:
System.out.println("case2");
break;
}
}
}
2 Answer
public class App {
/**
* The start point of the program
*
* @param args
*/
public static void main(String[] args) {
char g = 'a';
switch (g)
{
case 'r':
System.out.println("case1");
break;
case 'u':
System.out.println("case2");
break;
default:
System.out.println("default");
}
}
}
Comments
Leave a comment