Advertisement
Guest User

Untitled

a guest
Dec 14th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.19 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package apprefugiados;
  7.  
  8. import java.io.BufferedReader;
  9. import java.io.IOException;
  10. import java.io.InputStreamReader;
  11. import java.io.*;
  12.  
  13.  
  14. public class Ler {
  15.  
  16.  
  17.  
  18. public static String umaString() {
  19. String s = "";
  20. try {
  21. BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
  22. s = in.readLine();
  23. } catch (IOException e) {
  24. System.out.println("Erro ao ler fluxo de entrada.");
  25. }
  26. return s;
  27. }
  28.  
  29. public static int umInt() {
  30. while (true) {
  31. try {
  32. return Integer.valueOf(umaString().trim());
  33. } catch (NumberFormatException e) {
  34. System.out.println("Não é um inteiro válido!!!");
  35. }
  36.  
  37. }
  38. }
  39.  
  40. public static double umDouble() {
  41. while (true) {
  42. try {
  43. return Double.parseDouble(umaString().trim());
  44. } catch (NumberFormatException e) {
  45. System.out.println("Não é um double válido!!!");
  46. }
  47.  
  48. }
  49. }
  50.  
  51. public static double umFloat() {
  52. while (true) {
  53. try {
  54. return Float.parseFloat(umaString().trim());
  55. } catch (NumberFormatException e) {
  56. System.out.println("Não é um real válido!!!");
  57. }
  58.  
  59. }
  60. }
  61.  
  62. public static double umByte() {
  63. while (true) {
  64. try {
  65. return Byte.parseByte(umaString().trim());
  66. } catch (NumberFormatException e) {
  67. System.out.println("Não é um byte válido!!!");
  68. }
  69.  
  70. }
  71. }
  72.  
  73. public static double umShort() {
  74. while (true) {
  75. try {
  76. return Short.parseShort(umaString().trim());
  77. } catch (NumberFormatException e) {
  78. System.out.println("Não é um short válido!!!");
  79. }
  80.  
  81. }
  82. }
  83.  
  84. public static double umLong() {
  85. while (true) {
  86. try {
  87. return Long.parseLong(umaString().trim());
  88. } catch (NumberFormatException e) {
  89. System.out.println("Não é um long válido!!!");
  90. }
  91.  
  92. }
  93. }
  94.  
  95. public static char umChar() {
  96. while (true) {
  97. try {
  98. char c = umaString().trim().charAt(0);
  99.  
  100. return c;
  101. } catch (Exception e) {
  102. System.out.println("Não é um valor valido");
  103. }
  104. }
  105. }
  106.  
  107. public static boolean umBoolean() {
  108.  
  109. while (true) {
  110. try {
  111. boolean b;
  112. b = Boolean.parseBoolean(umaString().trim());
  113. if (b == true) {
  114. return true;
  115. }
  116. if (b == false) {
  117. return false;
  118. }
  119.  
  120. } catch (Exception e) {
  121. System.out.println("Não é um valor valido!");
  122. }
  123. }
  124.  
  125. }
  126. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement