A
A
Artur Martynov2015-11-29 15:33:49
Java
Artur Martynov, 2015-11-29 15:33:49

Why does a simple java calculator not work?

Help me figure out what's wrong and how to do it.

import java.util.Scanner;

public class Main {
  
  public static void main(String[] args) {
    // TODO Auto-generated method stub
    int result;
    String doing;
    int FirstNumber;
    int SecondNumber;
    
    
    String a = "+";
    String b = "-";
    String c = "*";
    String d = ":";
    Scanner scn = new Scanner(System.in);
    System.out.println("Введите первое число");
    FirstNumber = scn.nextInt();
    System.out.println("Введите второе число");
    SecondNumber = scn.nextInt();
    System.out.println("Введите действие");
    doing = scn.next();
    if (doing == a){
      result = FirstNumber + SecondNumber;
      System.out.println(result);
    }
    if (doing == b){
      result = FirstNumber - SecondNumber;
      System.out.println(result);
    }
    if (doing == c){
      result = FirstNumber * SecondNumber;
      System.out.println(result);
    }
    if (doing == d){
      result = FirstNumber / SecondNumber;
      System.out.println(result);
    }
    
    
  }

}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question