English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

4 answers

Switch case in any OOP language can accept only integers and characters.

2006-10-19 21:34:53 · answer #1 · answered by Anonymous · 0 0

The first answer to your question is correct. java will NOT accept String in a switch. don't forget that char is single quote.

char condition = 'b';
decideMe( condition );

public decideMe( char condition) {
switch( condition ) {
case 'a' : System.out.println("Houston, we have an A");
break;
default : System.out.println("Houston, we have a problem");
}
}

And, to convert back to char from a String takes a charArray();

java is picky on the Types of vars (which is good);

2006-10-20 04:53:21 · answer #2 · answered by Anonymous · 0 0

gwalker30...Read it and learn. Here is your link

http://www.google.co.uk/search?hl=en&q=use+switch%2Fcases+in+java+to+accept+and+pass+strings&btnG=Search&meta=

2006-10-20 06:45:44 · answer #3 · answered by Joe_Young 6 · 0 0

switch(STRING VARIABLE)
{
case 'VALUE1':COMMAND1;break;
case 'VALUE2':COMMAND2;break;
case 'VALUE3':COMMAND3;break;
default: COMMAND4;//it is executed if non of above 3 cases do not meet your condition.
//STRING VARIABLE should be a char.
}

2006-10-20 04:38:07 · answer #4 · answered by Amir M 2 · 0 0

fedest.com, questions and answers