Link to home
Start Free TrialLog in
Avatar of skychan
skychan

asked on

select case

hı everbody
i want to use case but i dont know syntax for select case
Could yo tell me how do i use
thankxx
Avatar of ldbkutty
ldbkutty
Flag of India image

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
Avatar of skychan
skychan

ASKER

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
ASKER CERTIFIED SOLUTION
Avatar of ldbkutty
ldbkutty
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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";
why just B !?