Answer to Question #253621 in Java | JSP | JSF for Sara

Question #253621

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
Expert's answer
2021-10-19T15:19:32-0400
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");
		}


	}


}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS