Note that you store the age (10) in the String age Then later you change the
String age to "Your age is 10" that is perfectly OK.   But.. then you try to
parse the String age to an Integer and "Your age is 10" is not parseable to
an Integer..

What you have to do is to store the age and the display string "Your age is
..." in different Strings.

Hope this will explain

Regards
  - Halli


        String age = "";
        age = JOptionPane.showInputDialog ("Please enter your age");
        *age = "Your age is " + age*;
        JOptionPane.showMessageDialog (null, age);

        *int ageint = Integer.parseInt(age);*


2009/9/7 Charles Polidano <[email protected]>

> Hi all
>
> I have been trying to work it out all day but output error displays the
> following :
>
> run:
> Exception in thread "main" java.lang.NumberFormatException: For input
> string: "Your age is 10"
>         at
> java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
>         at java.lang.Integer.parseInt(Integer.java:449)
>         at java.lang.Integer.parseInt(Integer.java:499)
>         at
> GetInputFromKeyboardJOptionPane2.main(GetInputFromKeyboardJOptionPane2.java:28)
> Java Result: 1
> BUILD SUCCESSFUL (total time: 7 seconds)
>
> This is my program code:
>
> /*
>  * To change this template, choose Tools | Templates
>  * and open the template in the editor.
>  */
> import javax.swing.JOptionPane;
>
> /**
>  *
>  * @author Compuline
>  */
> public class GetInputFromKeyboardJOptionPane2 {
>
>     /**
>      * @param args the command line arguments
>      */
>     public static void main(String[] args) {
>         String name = "";
>         name = JOptionPane.showInputDialog ("Please enter your name");
>         String msg = "Hello " + name + "!";
>         JOptionPane.showMessageDialog (null, msg);
>
>         String age = "";
>         age = JOptionPane.showInputDialog ("Please enter your age");
>         age = "Your age is " + age;
>         JOptionPane.showMessageDialog (null, age);
>
>         int ageint = Integer.parseInt(age);
>         if (ageint>100){
>             age = "Hello"+name+"Your age is"+age+"You are old";
>             JOptionPane.showMessageDialog(null,age);
>         }else{
>             age = "Hello"+name+"Your age is"+age+"You are young";
>             JOptionPane.showMessageDialog(null,age);
>         }
>
>
>         }
>     }
>
> cAN SOMEONE PLS HELP ME, AM I MISSING ON SOMETHING HERE ?
>
>
>
> ------------------------------
> check out the rest of the Windows Live™. More than mail–Windows Live™ goes
> way beyond your inbox. More than 
> messages<http://www.microsoft.com/windows/windowslive/>
> >
>

--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/javaprogrammingwithpassion?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to