List of usage examples for java.lang Double parseDouble
public static double parseDouble(String s) throws NumberFormatException
From source file:Main.java
public static void main(String[] argv) throws Exception { double d = Double.parseDouble("123.4e10"); System.out.println(d);/*from ww w .j a v a 2 s . c o m*/ }
From source file:Main.java
public static void main(String[] args) { String str = "50.00001"; double retval = Double.parseDouble(str); System.out.println("Value = " + retval); }
From source file:Main.java
public static void main(String[] args) { String str1 = "123.45"; try {/*from w ww. ja va 2 s.co m*/ double value1 = Double.parseDouble(str1); System.out.println("value1 = " + value1); } catch (NumberFormatException e) { System.out.println("Error in parsing " + str1); } String str2 = "8H.9"; // An invalid double try { double value2 = Double.parseDouble(str2); System.out.println("value2 = " + value2); } catch (NumberFormatException e) { System.out.println("Error in parsing " + str2); } }
From source file:Main.java
public static void main(String[] args) { List<String> stringList = Arrays.asList("1.2", "2.2", "3", "4", "5"); stringList.stream().mapToDouble(n -> Double.parseDouble(n)).filter(n -> n % 2 == 0) .forEach(System.out::println); }
From source file:Main.java
public static void main(String[] args) { Stream<String> s = Stream.of("1", "2", "3"); double o = s.collect(Collectors.summingDouble(n -> Double.parseDouble(n))); System.out.println(o);// w ww. jav a2 s . c om }
From source file:Main.java
public static void main(String[] args) { Stream<String> s = Stream.of("1", "2", "3"); double o = s.collect(Collectors.averagingDouble(n -> Double.parseDouble(n))); System.out.println(o);/*from ww w . ja v a 2 s . c o m*/ }
From source file:Main.java
public static void main(String[] args) { Double dObj1 = new Double("100.564"); System.out.println(dObj1);/* w w w .ja va 2 s . co m*/ Double dObj2 = Double.valueOf("10.6"); System.out.println(dObj2); double d = Double.parseDouble("76.39"); System.out.println(d); }
From source file:Main.java
public static void main(String[] args) { List<String> stringList = Arrays.asList("1.2", "2.2", "3", "4", "5"); stringList.stream().flatMapToDouble(n -> DoubleStream.of(Double.parseDouble(n))) .forEach(System.out::println); }
From source file:Main.java
public static void main(String[] argv) throws Exception { String age = "1"; String height = "1.5"; String weight = "5.9"; int theAge = Integer.parseInt(age); float theHeight = Float.parseFloat(height); double theWeight = Double.parseDouble(weight); System.out.println("Age: " + theAge); System.out.println("Height: " + theHeight); System.out.println("Weight: " + theWeight); }
From source file:Main.java
public static void main(String[] args) throws Exception { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); String input = reader.readLine(); double number = Double.parseDouble(input); System.out.println(input + ":" + Math.sqrt(number)); reader.close();// w w w . ja v a 2 s . c om }