Switch or If Else statement

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Michaelcis06
    New Member
    • Dec 2006
    • 1

    #1

    Switch or If Else statement

    I am a student in Trinidad who must learn and use Java as part of the Diploma in Computer Information Systems. I am having some problems in writing a Java Program for a salary and salary deduction. I have done most of the work and it is just the part where iI take out the decduction weekly which is also compounde weekly that is posing a problem. I am torn between using a swich statement or and if else statement.

    If any one can help, I wil be happy to share my source code and and would be grateful for any assistance.

    I use Windows XP
  • MMcCarthy
    Recognized Expert MVP
    • Aug 2006
    • 14387

    #2
    Originally posted by Michaelcis06
    I am a student in Trinidad who must learn and use Java as part of the Diploma in Computer Information Systems. I am having some problems in writing a Java Program for a salary and salary deduction. I have done most of the work and it is just the part where iI take out the decduction weekly which is also compounde weekly that is posing a problem. I am torn between using a swich statement or and if else statement.

    If any one can help, I wil be happy to share my source code and and would be grateful for any assistance.

    I use Windows XP
    I am moving this question to the Java forum where it is more likely to be answered.

    Mary

    Comment

    • horace1
      Recognized Expert Top Contributor
      • Nov 2006
      • 1510

      #3
      Originally posted by Michaelcis06
      I am a student in Trinidad who must learn and use Java as part of the Diploma in Computer Information Systems. I am having some problems in writing a Java Program for a salary and salary deduction. I have done most of the work and it is just the part where iI take out the decduction weekly which is also compounde weekly that is posing a problem. I am torn between using a swich statement or and if else statement.

      I use Windows XP
      Use a switch statement when carrying out a selection based on integral expressions:
      Code:
           switch (expression)
               {
                case constant1: statement1
                case constant2: statement2
                case constant3: statement3
                ......
                default: default_statement
               }
      where expression should evaluate to an integral value (using a cast if necessary) and constant1, constant2, etc. should be integral constant expressions, i.e. which evaluate to an integral constant at compile time.

      An if-then-else statement can be used to make decisions based on ranges of values or conditions, e.g. if (a > b), if (a < = b && c > d), etc

      Comment

      Working...