Hola:
Quiero hacer mi primer ejemplo con Java con esta operación:
int x = 10;
int prueba = x**4 + x**3 + (1/2.0) * x**2 - x;
Lo he intentado hacer con este código completo en NetBeans 6.9.1.
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package acaymo_01;
/**
*
* @author Hunter
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
int x = 10;
int prueba = x**4 + x**3 + (1/2.0) * x**2 - x;
}
}
Me sale este error:
Citarrun:
Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - possible loss of precision
required: int
found: double
at acaymo_01.Main.main(Main.java:20)
Java Result: 1
GENERACIÓN CORRECTA (total time: 2 seconds)
¿Cuál es el problema?
Lo que debo hacer es mostrar el resultado en pantalla.
Saludo.
Al hacer (1/2.0), como esa operacion no es entre enteros, lo convierte a double.
Pon int prueba = (int)(x**4 + ... - x);
Gracias.