Advertisement
Guest User

Untitled

a guest
Oct 30th, 2014
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. //Exercise ten, using strings to give instrustions
  2. import java.util.Scanner;
  3.  
  4. public class num2assign
  5. {
  6. public static void main(String[] args)
  7. {
  8. Scanner keyboard = new Scanner(System.in);
  9. System.out.println("Please type add, subtract, or multiply: ");
  10. String action = keyboard.nextLine();
  11.  
  12. System.out.println("Please enter a number: ");
  13. double num1 = keyboard.nextDouble();
  14. System.out.println("Please enter a number: ");
  15. double num2 = keyboard.nextDouble();
  16.  
  17. String add, multiply, subtract;
  18.  
  19. if (action.equals("add")){
  20. System.out.println(num1 + " + " + num2 + "= " + (num1+num2));
  21. }
  22. else if (action.equals("subtract")){
  23. System.out.println(num1 + " - " + num2 + " = " + (num1-num2));
  24. }
  25. else if (action.equals("multiply")){
  26. System.out.println(num1 + " x " + num2 + " = " + (num1*num2));
  27. }
  28. else
  29. System.out.println("Error = intstructions not recongized." );
  30. }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement