I made a simple program, just to calculate a mathematical function so I get an exact result, but there were some complications in Java.
Digite o valor de x: 0.2 Exception in thread "main" java.util.InputMismatchException at java.util.Scanner.throwFor(Scanner.java:909) at java.util.Scanner.next(Scanner.java:1530) at java.util.Scanner.nextFloat(Scanner.java:2388) at funçaofx.funx.main(funx.java:15) C:\Users\Renan\AppData\Local\NetBeans\Cache.1\executor-snippets\run.xml:53: Java returned: 1 FALHA NA CONSTRUÇÃO (tempo total: 2 segundos)
Code:
package funçaofx;
import java.util.Scanner;
public class funx {
public static void main(String args[]){
float x;
float y;
Scanner input = new Scanner(System.in);
System.out.println("Digite o valor de x:");
x = input.nextFloat();
input.nextLine();
y = (x - ((x*(x - 1))/(2*x)));
System.out.println("valor calculado por F(x):"+y);
input.close();
}
}
I tried to put double
instead of float
(because I have to do a good calculation
However, the program gives the same problem, does anyone have any idea how
if this is resolved?
Note: If I put integers as 1 or 0 , the program executes normally, but by entering a more precise number as 0.2 or 0.0038 For example, this exception
appears.