Advertisement
vencinachev

Untitled

Sep 26th, 2019
307
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.36 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4.     public static void main(String[] args) {
  5.         /*
  6.         System.out.println("hello");   
  7.         Scanner scan = new Scanner(System.in);
  8.         double number = scan.nextDouble();
  9.         double text = Double.parseDouble(scan.next());     
  10.         String numberAsString = "55";
  11.         int numberAsInteger = Integer.parseInt(numberAsString);
  12.         System.out.println(numberAsInteger);
  13.         //String text = scan.next();
  14.         System.out.println("Number: " + number + " text: " + text);
  15.         */             
  16.         Scanner scan = new Scanner(System.in);
  17.         System.out.print("Enter operation: ");
  18.         char op = scan.next().charAt(0);       
  19.         System.out.print("Enter first number: ");
  20.         int numberOne = scan.nextInt();
  21.         System.out.print("Enter second number: ");
  22.         int numnerTwo = scan.nextInt();
  23.                
  24.         if(op == '+') {
  25.             System.out.print(numberOne + numnerTwo);
  26.             int sum = numberOne + numnerTwo;
  27.             System.out.print("result: " + sum);
  28.         }else if(op == '-') {
  29.             if(numberOne > numnerTwo) {
  30.                 System.out.print(numberOne - numnerTwo);
  31.             }else {
  32.                 System.out.print("Error");
  33.             }
  34.         }else if(op == '*') {
  35.             System.out.print(numberOne * numnerTwo);
  36.         }else if(op == '/') {
  37.             if(numberOne == 0 || numnerTwo == 0) {
  38.                 System.out.print("Error");
  39.             }else {
  40.                 System.out.print(numberOne / numnerTwo);
  41.             }  
  42.         }else {
  43.             System.out.print("Invalid operation !");
  44.         }
  45.                
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement