Scanner double Scan - Java java.util

Java examples for java.util:Scanner

Description

Scanner double Scan

Demo Code


//package com.java2s;
import java.util.*;

public class Main {
    public static double doubleScan(Scanner scan, String print) {
        double number = 0;
        boolean run = true;
        String satisfy;//ww w.j  a  v a 2 s.  c  o  m
        while (run) {
            try {
                System.out.print(print);
                number = scan.nextDouble();
                run = false;
            } catch (Exception ex) //Catch if the user does not enter a floating point for the number.
            {
                System.out.print("Please enter a number.");
                satisfy = scan.next();
                run = true;
            }
        }
        return number;
    }
}

Related Tutorials