Read double value from console and check the format : Double « Data Type « Java Tutorial






import java.io.BufferedReader;
import java.io.InputStreamReader;

class Main {
  public static void main(String args[]) throws Exception {
    InputStreamReader isr = new InputStreamReader(System.in);
    BufferedReader br = new BufferedReader(isr);

    while (true) {
      System.out.print("Radius? ");
      String str = br.readLine();
      double radius;
      try {
        radius = Double.valueOf(str).doubleValue();
      } catch (NumberFormatException nfe) {
        System.out.println("Incorrect format!");
        continue;
      }
      if (radius <= 0) {
        System.out.println("Radius must be positive!");
        continue;
      }
      System.out.println("radius " + radius);
      return;
    }
  }
}








2.12.Double
2.12.1.Java double: double is 64 bit double precision type and used when fractional precision calculation is required.
2.12.2.How to declare floating-point variables: double
2.12.3.Create a Double object using one of the below given constructors
2.12.4.Use Double constructor to convert double primitive type to a Double object.
2.12.5.Double value
2.12.6.Demonstrate isInfinite() and isNaN()
2.12.7.Java Double isInfinite
2.12.8.Convert double value to string and check the position of dot
2.12.9.Java Double isNaN method
2.12.10.Java Double compare example
2.12.11.Format double with System.out.format
2.12.12.Trigonometric Demo
2.12.13.Decimal Format
2.12.14.Min and Max values of data type double
2.12.15.Convert java Double to numeric primitive data types
2.12.16.Convert Java String to Double
2.12.17.Convert from double to String
2.12.18.Convert from String to double
2.12.19.Converting a String to a double type Number
2.12.20.Use toString method of Double class to convert Double into String.
2.12.21.Compare Two Java double Arrays
2.12.22.Ternary operator on double value
2.12.23.Read double value from console and check the format