Should convert String to Int in java @ 1.5 or use other method?
<p>I'm writing a program in which I want to terminate program by pressing any key(whether character or numbers), so I did a conversion from string to int using <strong>Integer.parseInt(variable)</strong> method and compare choices if it is not desired choice it should terminate the program but it show an error <strong>Exception in thread "main" java.lang.NumberFormatException: for input string: "d"</strong>.</p>

<p>program code is as follows:-</p>

<pre><code>public class mainClass {
    public static void main( String[] ar ) {
        double res = 0;
        Scanner in = new Scanner( System.in );
        Tdata td1 = new Tdata(); // another class object

        System.out.println( "****Temperature Conversion****" );
        System.out.println( "------------------------------" );
        System.out.println( "Press 1-&gt; C2F" );
        System.out.println( "Press 2-&gt; F2C" );
        System.out.println( "&lt;- Press aNY kEY TO Exit -&gt;" );

        String choice = in.nextLine();

        // =======================================================
        int ch = Integer.parseInt( choice );
        System.out.println( "String has converted: " + ch ); 
        // verifying if converted into int
        if( ch == 1 || ch == 2 ) {
            if( ch == 1 ) {
                td1.getVal( 37.4 );
                res = td1.C2F();
                System.out.println( "Resulted Temperature: " + res );
            }
            else if( ch == 2 ) {
                td1.getVal( 104.2 );
                res = td1.F2C();
                System.out.println( "Resulted Temperature: " + res );
            }
            else {
                System.out.println( "mind your input plz" );
            }
        }
        else {

            System.out.println( "&lt;- You select to exit -&gt;" );
            System.exit( 0 );
        }
        // =======================================================
    }// end of main
}// end of public class
</code></pre>

<p>Now I think that I should convert undesired input to its previous state ie. String state.. is it right way or should Try another predefined method available in <em>api</em>.</p>

<p>-Thanks!
 Niks</p>
