Solved

select case

Posted on 2004-09-17
6
193 Views
Last Modified: 2012-05-05
hı everbody
i want to use case but i dont know syntax for select case
Could yo tell me how do i use
thankxx
0
Comment
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
  • Learn & ask questions
  • 4
6 Comments
 
LVL 32

Expert Comment

by:ldbkutty
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 52

Expert Comment

by:Ryan Chong
ID: 12082387
0
 

Author Comment

by:skychan
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 32

Accepted Solution

by:
ldbkutty earned 30 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

by:ldbkutty
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

by:ldbkutty
ID: 12082934
why just B !?
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
After seeing many questions for JRNL_WRAP_ERROR for replication failure, I thought it would be useful to write this article.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question