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 ;