Solved

select case

Posted on 2004-09-17
6
189 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
  • 4
6 Comments
 
LVL 32

Expert Comment

by:ldbkutty
Comment Utility
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 49

Expert Comment

by:Ryan Chong
Comment Utility
0
 

Author Comment

by:skychan
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 32

Accepted Solution

by:
ldbkutty earned 30 total points
Comment Utility
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
Comment Utility
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
Comment Utility
why just B !?
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Scam emails are a huge burden for many businesses. Spotting one is not always easy. Follow our tips to identify if an email you receive is a scam.
In this article, I will show you HOW TO: Create your first Windows Virtual Machine on a VMware vSphere Hypervisor 6.5 (ESXi 6.5) Host Server, the Windows OS we will install is Windows Server 2016.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now