Open file and read Double data
<p>Trying to read double data from the file that has different contents. For example if it is a double then the message should be  "Double number is 23.5". and if it is not double number the message should be "Sixty three is not a double number". The file contents are </p>

<p>97.9</p>

<p>100.1</p>

<p>Three   </p>

<p>Sixty three</p>

<p>77</p>

<p>12.4</p>

<p>3002.4</p>

<p>76</p>

<p>Cool</p>

<p>34.6</p>

<p>This is it</p>

<p>............</p>

<p>The code i wrote opens the file and scans next line But does not seem to properly work.</p>

<pre><code>class ReadDouble 
 {

 Scanner scan = new Scanner(System.in);


try

{

    File textFile = new File ("doubleData.txt");
    Scanner scanFile = new Scanner (textFile);
    String str = scan.nextLine();

    while(scanFile.hasNextLine())
    {

        double num = Double.parseDouble(str);
        if(str == num)
        {
            System.out.println("Double number is" + str);
        }

    }//end while


}//end try

catch (NumberFormatException nfe)
{
   System.out.println(str + "Is not a Double number");
}
</code></pre>

<p>}</p>

<p>}//end class</p>
