answersLogoWhite

0


Best Answer

public class NewClass {

public static void main(String[] arg) {

char grade = 'b';

switch (grade) {

case 'a' : System.out.println("Great Work!");

break;

case 'b' : System.out.println("Good Job!");

break;

case 'c' : System.out.println("Maybe Next Time!");

break;

case 'd' : System.out.println("Try Again!");

break;

case 'f' : System.out.println("No Comment!");

break;

}

}

}

User Avatar

Wiki User

12y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you use char in switch statement?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Is The controlling expression for a switch statement can be a char?

char is actually integer, even so they are represented with letters. Anyway, yes you can use the controlling expression of type char in switch statements.


Could you use char variablewith switch?

But of course.


What is the difference between 'switch' statement and 'if' statement?

we can use switch statement in multiple time but in if statement we can not use multiple time


Can a continue statement be used in a switch statement?

If you have a loop in your switch statement or around your switch statement, you can use the continue statement in that. You cannot use a continue statement outside of a loop (do, for, or while).


What is the purpose of Continue and break statement in C?

The break statement is frequently used to terminate the processing of a particular case within a switch statement. Lack of an enclosing iterative or switch statement generates an error.Within nested statements, the break statement terminates only the do, for, switch, or whilestatement that immediately encloses it. You can use a returnor goto statement to transfer control elsewhere out of the nested structure.This example illustrates the break statement:#include int main() { char c; for(;;) { printf_s( "\nPress any key, Q to quit: " ); // Convert to character value scanf_s("%c", &c); if (c == 'Q') break; } } // Loop exits only when 'Q' is pressed


What programming languages use a C switch statement?

There are two programming languages which use a C switch statement. The two languages are C and C++, hence the name C switch statement. There may be more, but those are the most obvious ones


Why not use the ampression symbol in scanf statement in function?

scanf is a function, not a statement. Example: int a; char name[12]; scanf ("%d %s", &a, &name[0]);


What is the use of switch statement in java?

In java, a switch statement is used to simplify a long list of 'if' statements. A switch statement takes the form of:switch (variableName){case condition1; command1;case condition2; command2;...}


In command prompt what does the if switch do?

There is not switch called "if". We generally use "if" statement in batch programming in DOS.


The break statement is required in the default case of a switch selection structure?

Ends the case statement. Without it, any code after where the break; is supposed to be will get executed as well until it does encounter a break; or the end of the switch.Code Example:char cTest = 'a';switch(cTest) {case 'a':/* Code here gets executed. */case 'b': //* Code here gets executed. */case 'c':/* Code here gets executed. */break;case 'd':/* Code here won't be executed. */default:/* Code here won't be executed. */}


How do you choose multiple if statement and switch statement?

If you must evaluate two or more expressions separately, use multiple if statements. If you only need to test all the possible evaluations of a single expression, use a switch.


How can we use characters in the switch statements to select the cases java?

Switch statements in Java can only use integer values. This means that we can switch on char values (because chars are simply ints with a different output type), but we can not switch on Strings or any other objects. The following examples are both valid in Java. // switch 1 int x = 1; switch(x) { case 0: break; case 1: break; default: break; } // switch 2 char x = '1'; switch(x) { case '0': break; case '1': break; default: break; }