Results 1 to 3 of 3

Thread: Switch

  1. #1
    KillerToFu_xX is offline Member
    Join Date
    Mar 2013
    Posts
    1
    Rep Power
    0

    Default Switch

    Solved
    Last edited by KillerToFu_xX; 03-19-2013 at 03:52 AM.

  2. #2
    Filoflow is offline Member
    Join Date
    Mar 2013
    Posts
    10
    Rep Power
    0

    Default Re: Switch

    I am sure that everybody will learn from this experience...

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,193
    Rep Power
    19

    Default Re: Switch

    Quote Originally Posted by KillerToFu_xX View Post
    Solved
    The original post was:
    Quote Originally Posted by KillerToFu_xX View Post
    Trying to figure out if i can make a switch statement do the fallowing code but i'm not sure how i can make the switch read my variables.

    import java.util.Scanner;

    public class question3
    {
    public static void main(String[] args)
    {
    System.out.println(" Please select one of these options.");
    System.out.println(" 1. Press A to add three numbers ");
    System.out.println(" 2. Press S to subtract two numbers ");
    System.out.println(" 3. Press M to multiply by three numbers ");
    System.out.println(" 4. Press D to divide by two numbers ");
    System.out.println(" 5. Press O to modulus two numbers ");
    System.out.println(" 6. Press E to quit the program ");
    System.out.println(" ");

    Scanner input = new Scanner( System.in );
    String aString = input.next();
    char choice = aString.charAt(0);


    switch (option)
    {
    case 'A': {
    addition (); }
    break;
    case 'S': {
    subtract (); }
    break;
    case 'M': {
    multiply (); }
    break;
    case 'D': {
    divide (); }
    break;
    case 'O': {
    modulus (); }
    break;
    case 'E': {
    quit ();}
    break;
    default: }

    }

    public static void addition(){
    Scanner input = new Scanner( System.in );
    float number1;
    float number2;
    float number3;
    float sum;

    System.out.printf( "Enter first interger: " );
    number1 = input.nextInt();
    System.out.printf( "Enter second interger: " );
    number2 = input.nextInt();
    System.out.printf( "Enter Third interger: " );
    number3 = input.nextInt();

    sum = number1 + number2 + number3;
    System.out.printf( "Sum equals %f\n", sum);
    }
    public static void subtract(){
    Scanner input = new Scanner( System.in );
    float number1;
    float number2;
    float difference;

    System.out.printf( "Enter number to be subtracted: " );
    number1 = input.nextInt();
    System.out.printf( "Enter interger to subtract: " );
    number2 = input.nextInt();


    difference = number1 - number2;
    System.out.printf( "The difference is %f\n", difference);

    }
    public static void multiply(){
    Scanner input = new Scanner( System.in );
    float number1;
    float number2;
    float number3;
    float product;

    System.out.printf( "Enter first interger to multiply: " );
    number1 = input.nextInt();
    System.out.printf( "Enter second interger: " );
    number2 = input.nextInt();
    System.out.printf( "Enter Third interger: " );
    number3 = input.nextInt();

    product = number1 * number2 * number3;
    System.out.printf( "The product is %f\n", product);

    }

    public static void divide(){
    Scanner input = new Scanner( System.in );
    float number1;
    float number2;
    float dividen;

    System.out.printf( "Enter first interger: " );
    number1 = input.nextInt();
    System.out.printf( "Enter second interger: " );
    number2 = input.nextInt();

    dividen = number1 / number2;
    System.out.printf( "The dividen equals %f\n", dividen);

    }

    public static void modulus(){
    Scanner input = new Scanner ( System.in );
    float number1;
    float number2;
    float sum;

    System.out.printf( "Enter first interger: " );
    number1 = input.nextInt();
    System.out.printf( "Enter second inerger: " );
    number2 = input.nextInt();

    sum = number1 % number2;
    System.out.printf( "The answer equals %f\n", sum);

    }

    public static void quit(){
    System.out.printf( "Thank you for trying to use the program.");
    return;

    }

    }
    Any ideas would be sweet thanks!
    For your future reference, please go through the following:
    Forum Rules
    Guide For New Members
    BB Code List - Java Programming Forum - Learn Java Programming

    db

    THREAD CLOSED
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Switch
    By java4amanda in forum New To Java
    Replies: 13
    Last Post: 03-21-2012, 09:53 AM
  2. Help with switch cases
    By bossanova in forum New To Java
    Replies: 9
    Last Post: 11-06-2010, 02:43 AM
  3. switch
    By dj kourampies in forum New To Java
    Replies: 17
    Last Post: 01-30-2009, 05:32 PM
  4. switch
    By dj kourampies in forum New To Java
    Replies: 2
    Last Post: 01-30-2009, 08:46 AM
  5. Switch help please!!!!
    By soc86 in forum New To Java
    Replies: 6
    Last Post: 11-23-2008, 07:25 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •