fork download
  1. import java.util.*;
  2. import java.io.*;
  3. import java.text.NumberFormat;
  4.  
  5. class Ideone
  6. {
  7. public static void main (String[] args) throws java.lang.Exception
  8. {
  9. float x, y;
  10.  
  11. NumberFormat nformat = NumberFormat.getInstance(Locale.GERMAN);
  12. Scanner input = new Scanner(System.in);
  13.  
  14. System.out.println("Digite o valor de x: ");
  15.  
  16. try {
  17. x = input.nextFloat();
  18. } catch (InputMismatchException err) {
  19. x = nformat.parse(input.nextLine()).floatValue();
  20. // err.printStackTrace();
  21. }
  22.  
  23. y = (x - ((x* (x - 1)) / (2* x)));
  24.  
  25. System.out.println("valor calculado por F(x): " + y);
  26. input.close();
  27. }
  28. }
Success #stdin #stdout 0.07s 321344KB
stdin
0.2
stdout
Digite o valor de x: 
valor calculado por F(x): 0.6