my dog learned polymorphism*
The moose likes Beginning Java and the fly likes HELP!!!! how does Character.isLetter work? (need experts) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "HELP!!!! how does Character.isLetter work? (need experts)" Watch "HELP!!!! how does Character.isLetter work? (need experts)" New topic
Author

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

leo dacullo
Greenhorn

Joined: Jul 09, 2009
Posts: 6
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

Joined: Jul 08, 2003
Posts: 24166
    
  30



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?


[Jess in Action][AskingGoodQuestions]
leo dacullo
Greenhorn

Joined: Jul 09, 2009
Posts: 6
can you please teach me with exception...
and help me to encode my problem... please sir?
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18117
    
  39

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


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
leo dacullo
Greenhorn

Joined: Jul 09, 2009
Posts: 6
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

Joined: Oct 02, 2003
Posts: 10916
    
  12

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


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
leo dacullo
Greenhorn

Joined: Jul 09, 2009
Posts: 6
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
Sheriff

Joined: Sep 28, 2004
Posts: 18117
    
  39

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

Joined: Jul 09, 2009
Posts: 6
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

Joined: Oct 13, 2005
Posts: 36499
    
  16
Have you read the documentation for that method? Please fill in this code
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18117
    
  39

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: HELP!!!! how does Character.isLetter work? (need experts)
 
Similar Threads
Triangle Perimeter HELP!!!
Need help creating classes
The method showMessageDialog(Component, Object) in the type JOptionPane is not applic
JOptionPane dialog box is not displaying
Methods