2
I made a simple program, just to calculate a mathematical function to 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\8.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 get a double
instead of float
(because I need to do a good calculation
), but the program gives the same problem, someone has some idea how to
whether to solve this?
Note: If I put integers as 1 or 0, the program runs normally, but when placing a more precise number like 0.2 or 0.0038 for example, appears this exception
.
I am using netbeans and am using with stitch
– ReZ
@Rez try with comma, here it worked.
– user28595
@Rez has to be with the same comma!
– viana
@Rez I spoke, but I corrected right after I took the test. Using the comma, should fix your problem.
– viana
Ow vlws kara,é even,put with comma in netbeans and the stop gave no problem
– ReZ
@Rez need, just come here and give a shout. Hugs. Good Luck!
– viana