Hey guys,
Thanks a lot Antonio and you Shyam. It was that String msg that i was missing, instead i was declaring age more then once, so taht was the problem. Until Shyam corrected it as String ageStr (anotehr variable name for the output display) Thanks again Shyam. God day ! :) From: [email protected] To: [email protected]; [email protected] Subject: [java programming] RE: Topic 2 - Homework : Getting input from keyboard via JOptionPane - HELP pls ! Date: Tue, 8 Sep 2009 09:01:51 +0530 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 Live™. More than mail–Windows Live™ goes way beyond your inbox. More than messages _________________________________________________________________ Drag n’ drop—Get easy photo sharing with Windows Live™ Photos. http://www.microsoft.com/windows/windowslive/products/photos.aspx --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
