Dear Charles,

 

The corrected file is as follows:

 

 

import javax.swing.JOptionPane;

 

/*

 * To change this template, choose Tools | Templates

 * and open the template in the editor.

 */

 

/**

 *

 * @author Shyam

 */

public class GetInputFromKeyboardJOptionPane2 {

      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");


            String ageStr = "Your age is " + age;
// age was assigned here as string.

            JOptionPane.showMessageDialog (null, ageStr);

 

            int ageint;

            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);

            }

 

 

            }

 

}

 

Thanks & Regards,

 

Shyam 

 

 

From: Charles Polidano [mailto:[email protected]] 
Sent: Tuesday, September 08, 2009 4:46 AM
To: [email protected]; [email protected]
Subject: Topic 2 - Homework : Getting input from keyboard via JOptionPane -
HELP pls !

 

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 LiveT. More than mail-Windows LiveT goes
way beyond your inbox. More than
<http://www.microsoft.com/windows/windowslive/>  messages


--~--~---------~--~----~------------~-------~--~----~
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