views:

121

answers:

2
  switch ( choice )
    {
       case '+':
          System.out.printf( "The answer is: %1$.4f.\n", first + second );
          break;
       case '-':
          System.out.printf( "The answer is: %1$.4f.\n", first - second );
          break;
       case '*':
          System.out.printf( "The answer is: %1$.4f.\n", first * second );
          break;
       case '/':
          if( second != 0 )
            System.out.printf( "The answer is: %1$.4f.\n", first / second );
          else
            System.out.println( "Can't divide by zero." );
          break;
       default :
          System.out.println( "You have entered an invalid operation.  Try again." );
          break;
    }
+2  A: 

You can use the return; statement to terminate the function

For example:

case 'x':
    return;

You also need to wrap it all in while(true) { ... } to make it loop forever (until return;)

SLaks
+2  A: 
while (true)
{
    System.out.println("What type of Employee? Enter 'o' for Office " +
    "Clerical, 'f' for Factory, or 's' for Saleperson.  Enter 'x' to exit." );  
    String response= inp.nextLine().toLowerCase();

    // validate input, do you switch statement, return; on x     
}
Lauri Lehtinen
The switch statement is either inside this loop, or inside another method which is called from inside this loop.Looking at your code, this while loop would come after you declare the totalPay variable.
Lauri Lehtinen