Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
Solved

# select case

Posted on 2004-09-17
Medium Priority
195 Views
h&#305; everbody
i want to use case but i dont know syntax for select case
Could yo tell me how do i use
thankxx
0
Question by:skychan
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 4

LVL 32

Expert Comment

ID: 12082381
A switch statement has the form:
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's a power of 2!)");
break;
case 3:
case 6:
case 9:
System.out.println("The number is 3, 6, or 9.");
System.out.println("(That's a multiple of 3!)");
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
0

LVL 53

Expert Comment

ID: 12082387
0

Author Comment

ID: 12082440
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
0

LVL 32

Accepted Solution

ldbkutty earned 90 total points
ID: 12082567
if getString() method is used to retrieve a numeric type, it will convert the numeric value to a Java String object, and the value will have to be converted back to a numeric type before it can be operated on as a number. I think you need like this:

int birinci = Integer.parseInt(ga.getString(1));
switch (birinci) {
case 267:
mmtype="LEND";
break;
case 268:
mmtype="LEND";
break;
case 269:
mmtype="LEND";
break;
case 260:
mmtype="BORROW";
break;
case 198:
mmtype="BORROW";
break;
case 257:
mmtype="BORROW";
break;
default:  // optional default case
mmtype="UNKNOW";
}

Better is use if else instead of switch case for your code.
0

LVL 32

Expert Comment

ID: 12082584
int birinci = Integer.parseInt(ga.getString(1));
if(birinci == 267 || birinci == 268 || birinci == 269)
mmtype="LEND";
else if(birinci == 260 || birinci == 198 || birinci == 257)
mmtype="BORROW";
else
mmtype="UNKNOWN";
0

LVL 32

Expert Comment

ID: 12082934
why just B !?
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

One of the most important things in an application is the query performance. This article intends to give you good tips to improve the performance of your queries.
If something goes wrong with Exchange, your IT resources are in trouble.All Exchange server migration processes are not designed to be identical and though migrating email from on-premises Exchange mailbox to Cloud’s Office 365 is relatively simple…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
###### Suggested Courses
Course of the Month12 days, 4 hours left to enroll