Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- System.out.println("hello");
- Scanner scan = new Scanner(System.in);
- System.out.print("Enter operation");
- char symbol = scan.next().charAt(0);
- System.out.print("Enter first number: ");
- int number1 = Integer.parseInt(scan.next());
- System.out.print("Enter second number: ");
- int number2 = scan.nextInt();
- if(symbol == '+') {
- System.out.print(number1 + number2);
- }else if(symbol == '-') {
- if(number1 > number2) {
- System.out.print(number1 - number2);
- }else {
- System.out.print("First number mast be greater than second number");
- }
- }else if(symbol == '*') {
- System.out.print(number1 * number2);
- }else if(symbol == '/') {
- if(number2 != 0) {
- System.out.print(number1 / number2);
- }else {
- System.out.print("Second number can't be zero");
- }
- }else {
- System.out.print("Invalid operation");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement