Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Created by Julio Tentor <jtentor@fi.unju.edu.ar>
- //
- import java.util.Random;
- import java.util.Scanner;
- public class Work1 {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- float number1, number2 = 0;
- number1 = getFloat(scanner, "Ingrese el 1er número: ");
- number2 = getFloat(scanner, "Ingrese el 2do número: ");
- System.out.println("El 1er Número ingresado es " + number1);
- System.out.println("El 2do Número ingresado es " + number2);
- }
- static float getFloat(Scanner scanner, String message){
- float number = 0;
- while (true) {
- try {
- System.out.printf(message);
- number = Float.parseFloat(scanner.nextLine());
- } catch (Exception exception) {
- System.out.println("\nIngrese un número válido");
- continue;
- }
- break;
- }
- return number;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement