Solved

select case

Posted on 2004-09-17
6
190 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
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 49

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

What does UTC stand for?  “Coordinated Universal Time” – Think of this as the true time on Planet Earth that never changes with the exception of minor leap seconds here and there to account for the changes in the planet's rotation.   What does th…
Microsoft Office Picture Manager was included in Office 2003, 2007, and 2010, but not in Office 2013. Users had hopes that it would be in Office 2016/Office 365, but it is not. Fortunately, the same zero-cost technique that works to install it with …
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

910 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

21 Experts available now in Live!

Get 1:1 Help Now