skychan
asked on
select case
hı everbody
i want to use case but i dont know syntax for select case
Could yo tell me how do i use
thankxx
i want to use case but i dont know syntax for select case
Could yo tell me how do i use
thankxx
ASKER
int birinci = ga.getString(1);
switch (birinci) {
case 267,268,269:
mmtype="LEND";
break;
case 260,198,257:
mmtype="BORROW";
break;
default: // optional default case
mmtype="UNKNOW";
}
ERROR:
Error(166,34): incompatible types; found: java.lang.String, required: int
switch (birinci) {
case 267,268,269:
mmtype="LEND";
break;
case 260,198,257:
mmtype="BORROW";
break;
default: // optional default case
mmtype="UNKNOW";
}
ERROR:
Error(166,34): incompatible types; found: java.lang.String, required: int
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
int birinci = Integer.parseInt(ga.getStr ing(1));
if(birinci == 267 || birinci == 268 || birinci == 269)
mmtype="LEND";
else if(birinci == 260 || birinci == 198 || birinci == 257)
mmtype="BORROW";
else
mmtype="UNKNOWN";
if(birinci == 267 || birinci == 268 || birinci == 269)
mmtype="LEND";
else if(birinci == 260 || birinci == 198 || birinci == 257)
mmtype="BORROW";
else
mmtype="UNKNOWN";
why just B !?
switch (expression) {
case constant-1:
statements-1
break;
case constant-2:
statements-2
break;
.
. // (more cases)
.
case constant-N:
statements-N
break;
default: // optional default case
statements-(N+1)
} // end of switch statement
Here is an example of a switch statement. This is not a useful example, but it should be easy for you to follow. Note, by the way, that the constants in the case labels don't have to be in any particular order, as long as they are all different:
switch (N) { // assume N is an integer variable
case 1:
System.out.println("The number is 1.");
break;
case 2:
case 4:
case 8:
System.out.println("The number is 2, 4, or 8.");
System.out.println("(That'
break;
case 3:
case 6:
case 9:
System.out.println("The number is 3, 6, or 9.");
System.out.println("(That'
break;
case 5:
System.out.println("The number is 5.");
break;
default:
System.out.println("The number is 7,");
System.out.println(" or is outside the range 1 to 9.");
}
Referez and for more: http://math.hws.edu/eck/cs124/javanotes3/c3/s6.html