Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package apprefugiados;
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.io.*;
- public class Ler {
- public static String umaString() {
- String s = "";
- try {
- BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
- s = in.readLine();
- } catch (IOException e) {
- System.out.println("Erro ao ler fluxo de entrada.");
- }
- return s;
- }
- public static int umInt() {
- while (true) {
- try {
- return Integer.valueOf(umaString().trim());
- } catch (NumberFormatException e) {
- System.out.println("Não é um inteiro válido!!!");
- }
- }
- }
- public static double umDouble() {
- while (true) {
- try {
- return Double.parseDouble(umaString().trim());
- } catch (NumberFormatException e) {
- System.out.println("Não é um double válido!!!");
- }
- }
- }
- public static double umFloat() {
- while (true) {
- try {
- return Float.parseFloat(umaString().trim());
- } catch (NumberFormatException e) {
- System.out.println("Não é um real válido!!!");
- }
- }
- }
- public static double umByte() {
- while (true) {
- try {
- return Byte.parseByte(umaString().trim());
- } catch (NumberFormatException e) {
- System.out.println("Não é um byte válido!!!");
- }
- }
- }
- public static double umShort() {
- while (true) {
- try {
- return Short.parseShort(umaString().trim());
- } catch (NumberFormatException e) {
- System.out.println("Não é um short válido!!!");
- }
- }
- }
- public static double umLong() {
- while (true) {
- try {
- return Long.parseLong(umaString().trim());
- } catch (NumberFormatException e) {
- System.out.println("Não é um long válido!!!");
- }
- }
- }
- public static char umChar() {
- while (true) {
- try {
- char c = umaString().trim().charAt(0);
- return c;
- } catch (Exception e) {
- System.out.println("Não é um valor valido");
- }
- }
- }
- public static boolean umBoolean() {
- while (true) {
- try {
- boolean b;
- b = Boolean.parseBoolean(umaString().trim());
- if (b == true) {
- return true;
- }
- if (b == false) {
- return false;
- }
- } catch (Exception e) {
- System.out.println("Não é um valor valido!");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement