Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

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

 
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
 
author and iconoclast
Posts: 24203
43
Mac OS X Eclipse IDE Chrome
  • 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?
 
author
Posts: 23878
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux 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
 
lowercase baba
Posts: 12871
62
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
Posts: 23878
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux 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...
 
Marshal
Posts: 69782
277
  • 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
Posts: 23878
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux 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
 
Don't get me started about those stupid light bulbs.
    Bookmark Topic Watch Topic
  • New Topic