This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HELP!!!! how does Character.isLetter work? (need experts)

 
leo dacullo
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i really have this problem and i dont know how Character.isLetter work

and can you guys please help me with this code;

String num1, num2;
int numa, numb, div;
num1 = JOptionPane.showInputDialog("Enter first number");
num2 = JOptionPane.showInputDialog("Enter second number");
numa = Integer.parseInt(num1);
numb = Integer.parseInt(num2);
if(numb == 0){
JOptionPane.showMessageDialog(null,"The Answer is Undefine");}
else{
div = numa / numb;
JOptionPane.showMessageDialog(null,"The answer is: " + div);
System.exit(0);}


now... my problem is when you input a letter on the input dialog box a message box will appear saying "your input is invalid"...
please help me with this code...huhuhu
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


If you enter an invalid number, the calls to parseInt() will throw a NumberFormatException. You can simply catch those exceptions and ask the user to try to enter a number again. Have you learned about exceptions yet?
 
leo dacullo
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can you please teach me with exception...
and help me to encode my problem... please sir?
 
Henry Wong
author
Marshal
Pie
Posts: 20997
76
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is the Sun tutorial on exceptions....

http://java.sun.com/docs/books/tutorial/essential/exceptions/

Give it a read. Then give your example a go. And come back if you run into a problem.

Henry
 
leo dacullo
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
big help... thanks! but can you please give me a code for my problem as a reference? thanks in advance
 
fred rosenberger
lowercase baba
Bartender
Pie
Posts: 12097
30
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
we generally don't 'give out code'. We feel folks learn better if they try it on their own, post that, and then we give tips/suggestions/corrections.

So, read the examples and try it... maybe it will work!!! ;-)
 
leo dacullo
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok sir... as for my understanding i came up into this but there still an error...


String num1, num2;
int numa, numb, div;
num1 = JOptionPane.showInputDialog("Enter first number");
numa = Integer.parseInt(num1);
if(numa == Character.isLetter()){
JOptionPane.showMessageDialog(null,"Your input is Invalid");}
num2 = JOptionPane.showInputDialog("Enter second number");
numb = Integer.parseInt(num2);
if(numb == 0){
JOptionPane.showMessageDialog(null,"The Answer is Undefine");}
else{
div = numa / numb;
JOptionPane.showMessageDialog(null,"The answer is: " + div);
System.exit(0);}

i think that Character.isLetter() defines if the input is a letter...but i really dont know how this syntax works...any advice for a newbie or tip code? please sir need to know it badly..
 
Henry Wong
author
Marshal
Pie
Posts: 20997
76
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
any advice for a newbie or tip code? please sir need to know it badly..


Well, you pretty much decided to ignore my previous answer. And something tells me that if I do anything short of fixing your homework problem for you, you will probably ignore any hint / tip that I give you too.

Henry
 
leo dacullo
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
actually sir i really dont ignore your tips...i've read it but then as a newbie to the programming world, it too hard for me to understand it...the site has the explanation on exception but no samples...i hope you understand me sir...
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you read the documentation for that method? Please fill in this code
 
Henry Wong
author
Marshal
Pie
Posts: 20997
76
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
leo dacullo wrote:actually sir i really dont ignore your tips...i've read it but then as a newbie to the programming world, it too hard for me to understand it...the site has the explanation on exception but no samples...i hope you understand me sir...


The link is for a tutorial -- and as such it contains a lot of explanations. It also contains some really simple example codes at the end of the chapter.

Having lots of explanations and a few very simple examples .... is much better than that you are asking for... the code to fix your issue, with little to no explanation. No only will the explanation be lacking, but the sample is also not simple either.

The only advantage of what you are asking for is... your homework will be done. And you can move on without actually wasting time learning the subject.

Henry
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic