Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. import java.util.InputMismatchException;
  2. import java.util.Locale;
  3. import java.util.Scanner;
  4.  
  5. public class InputValue {
  6. //Declaración de Scanner
  7. public static Scanner sc = new Scanner(System.in);
  8.  
  9. public static void main(String[] args) {
  10. firstInput();
  11. sc.close();
  12. }
  13.  
  14. public static void firstInput() {
  15. Double number = 0.0;
  16. try {
  17. System.out.print("Introduce un número: ");
  18. sc.useLocale(Locale.US); //It's a dot .
  19. number = sc.nextDouble();
  20. if(number%2==0) {
  21. System.out.println("\t> " + number + " es par");
  22. } else {
  23. System.out.println("\t> " + number + " es impar");
  24. }
  25. }catch (InputMismatchException i) {
  26. secondInput(number);
  27. }catch (Exception e) {
  28. System.err.println("Error, no has introducido un número");
  29. }
  30. }
  31.  
  32. private static void secondInput(Double number) {
  33. try {
  34. System.out.print("Introduce un número: ");
  35. sc.useLocale(Locale.FRANCE); //It's a comma ,
  36. number = sc.nextDouble();
  37. if(number%2==0) {
  38. System.out.println("\t> " + number + " es par");
  39. } else {
  40. System.out.println("\t> " + number + " es impar");
  41. }
  42. }catch (Exception e) {
  43. System.err.println("Error, no has introducido un número");
  44. }
  45. }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement