Estoy atascado con este programa de cálculo, ahora no recibo la respuesta correcta

Elias heladas:

Mi curso de programación me quiere tener este tipo de endcome:

  • Introduzca el primer número!
  • 9
  • Introduzca el segundo número!
  • 5
  • 9 + 5 = 14
  • 9-5 = 4
  • 9 * 5 = 45
  • 9/5 = 1,8 y este es el problema, el programa que he escrito sólo me da 1,0 como respuesta. ¿Cómo puedo conseguir que este número es 1.8, no 1.0?

public class Nelilaskin {

    public static void main(String[] args) {
        Scanner reader = new Scanner(System.in);


        System.out.println("Enter the first number!");
        int first = Integer.valueOf(reader.nextLine());
        System.out.println("Enter the second number!");
        int second = Integer.valueOf(reader.nextLine());
        int plus = (first + second);
        int minus = (first - second);
        int multi = (first * second);
        double division = (first / second * 1.0);

        System.out.println(first + " + " + second + " = " + plus);
        System.out.println(first + " - " + second + " = " + minus);
        System.out.println(first + " * " + second + " = " + multi);
        System.out.println(first + " / " + second + " = " + division);


    }

}
Bashir:

esto es porque estás dividiendo dos valores int, intenta convertir al menos uno de ellos para duplicar ..

   double division = (double)first / (double)second ;

Supongo que te gusta

Origin http://43.154.161.224:23101/article/api/json?id=293168&siteId=1
Recomendado
Clasificación