The program takes a user input string, converts it to a double value using two different methods and prints the resulting double values
Here's a breakdown of the program:
import java.util.Scanner; public class StringToDouble { public static void main(String args[]) { Scanner input = new Scanner(System.in); String str; System.out.print("Enter the Number : "); str = input.next(); System.out.println("String Value : " + str); double dou_val = 0; //doubleValue() Method 1 dou_val = Double.valueOf(str).doubleValue(); System.out.println("Double Value Using doubleValue() Method : " + dou_val); //parseDouble() Method 2 dou_val = Double.parseDouble(str); System.out.println("Double Value Using parseDouble() Method : " + dou_val); } }
Enter the Number : 123.46321566 String Value : 123.46321566 Double Value Using doubleValue() Method : 123.46321566 Double Value Using parseDouble() Method : 123.46321566
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions