Solved

select case

Posted on 2004-09-17
6
191 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 50

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
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 
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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Export JSON response data to Excel in IE9 3 75
eclipse problems view not showing all the time 4 88
TreeSet comparator example 7 95
by zero exception 10 40
This tutorial shows how to create a greeting card by combining two image layers and a text layer on a PC using a free image editing app.
Read about the ways of improving workplace communication.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

770 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