Advertisement
Guest User

task2.java

a guest
Oct 23rd, 2011
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.16 KB | None | 0 0
  1. import java.io.IOException;
  2. import java.util.*;
  3.  
  4. public class task2 {
  5.     public static void main (String [] args) throws IOException {
  6.         int a;
  7.         int b;
  8.         String y;
  9.         String x;
  10.         Scanner input = new Scanner(System.in);
  11.  
  12.         System.out.println("Please enter number A:");
  13.         a = input.nextInt();
  14.  
  15.         System.out.println("\nPlease enter number B:");
  16.         b = input.nextInt();
  17.  
  18.         System.out.println("\nLastly, enter A if you wish it to be the dividor and/or subtractor, or if you wish it to be B, please enter B :");             //stops running properly here...
  19.         y=input.next();
  20.  
  21.         System.out.println("\nWhat would you like to do? Multiply (*), Divide (/), Subtract (-) or  Add   (+)? Please enter the symbol of which process you would like to have completed:");
  22.         x=input.next();
  23.  
  24.         if (y.equals("B")) {
  25.  
  26.             if (x.equals("*")) {
  27.                 System.out.println("\nThe product of these numbers is:" + a*b);}
  28.             else
  29.                 if (x.equals("/")) {
  30.                     System.out.println("\nThe quotient of these numbers is:" + a/b);}
  31.                 else
  32.                     if (x.equals("+")) {
  33.                         System.out.println("\nThe sum of these numbers is:" + a+b);}
  34.                     else
  35.                         if (x.equals("-")) {
  36.                             System.out.println("\nThe difference of these numbers is:" + (a-b));}}
  37.  
  38.         else
  39.             if (y.equals("A")){
  40.  
  41.                 if (x.equals("*")) {
  42.                     System.out.println("\nThe product of these numbers is:" + b*a);}
  43.                 else
  44.                     if (x.equals("/")) {
  45.                         System.out.println("\nThe quotient of these numbers is:" + b/a);}
  46.                     else
  47.                         if (x.equals("+")) {
  48.                             System.out.println("\nThe sum of these numbers is:" + b+a);}
  49.                         else
  50.                             if (x.equals("-")) {
  51.                                 System.out.println("\nThe difference of these numbers is:" + (b-a));
  52.                             }
  53.             }
  54.     }
  55. }
  56.  
  57.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement