Advertisement
vencinachev

Untitled

Sep 30th, 2019
275
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4.  
  5. public static void main(String[] args) {
  6.  
  7. System.out.println("hello");
  8. Scanner scan = new Scanner(System.in);
  9. System.out.print("Enter operation");
  10. char symbol = scan.next().charAt(0);
  11. System.out.print("Enter first number: ");
  12. int number1 = Integer.parseInt(scan.next());
  13. System.out.print("Enter second number: ");
  14. int number2 = scan.nextInt();
  15.  
  16. if(symbol == '+') {
  17. System.out.print(number1 + number2);
  18. }else if(symbol == '-') {
  19. if(number1 > number2) {
  20. System.out.print(number1 - number2);
  21. }else {
  22. System.out.print("First number mast be greater than second number");
  23. }
  24. }else if(symbol == '*') {
  25. System.out.print(number1 * number2);
  26. }else if(symbol == '/') {
  27. if(number2 != 0) {
  28. System.out.print(number1 / number2);
  29. }else {
  30. System.out.print("Second number can't be zero");
  31. }
  32. }else {
  33. System.out.print("Invalid operation");
  34. }
  35. }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement