The Artima Developer Community
Sponsored Link

Java Answers Forum
help needed

1 reply on 1 page. Most recent reply: Oct 31, 2003 3:47 AM by Joe Parks

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
Subha

Posts: 16
Nickname: nikki
Registered: Sep, 2003

help needed Posted: Oct 30, 2003 11:04 AM
Reply to this message Reply
Advertisement
if there are 8 cases given by a switch statement and each case gives me a value.how can i compare the values of each case statement as in find the minimum value?
for eg:

for(int i=1;i<=8;i++);
{
switch(i)
case1:value=2;break;
case2:value=4;break;
case3:v alue=3;break;
case4:value=7;break;
case5:value=8;break;
case6:value=9;break;
cas e7:value=6;break;
case8:value=12;break;
}

how do i find out the minimum value of the cases...
in this case it is case1.how can i find out?
pls help..


Joe Parks

Posts: 107
Nickname: joeparks
Registered: Aug, 2003

Re: help needed Posted: Oct 31, 2003 3:47 AM
Reply to this message Reply
int minValue = Integer.MAX_VALUE;
for(int i=1;i<=8;i++) {
    switch(i) {
        case 1:
          value=2;
          break;
        case 2:
          value=4;
          break;
        case 3:
          value=3;
          break;
        case 4:
          value=7;
          break;
        case 5:
          value=8;
          break;
        case 6:
          value=9;
          break;
        case 7:
          value=6;
          break;
        case 8:
          value=12;
          break;
    }
    if (value < minValue) {
        minValue = value;
    }
}

Flat View: This topic has 1 reply on 1 page
Topic: Replacement for getServletNames() / getServlets() Previous Topic   Next Topic Topic: java will not load in yahoo games

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use