Java Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingJava Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old May 14th, 2004, 03:11 PM
Yellow_Chicken Yellow_Chicken is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 2 Yellow_Chicken User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Java newbie needs help

Hi,
I just started learning java a week ago. I wrote a program that asks to input a character and it outputs the unicode number for it. I would like to know how to make it so the program shows an error message if the character entered by the user is not a letter(capital or lowercase) or a digit. Any help would be great. thanks

Heres my code so far
public class UnicodeConversion
{
public static void main(String[]args)
{

char Character;
int Unicode;

System.out.println("Please enter a character of your choice.");

// Ask for the input of a character
Character = SavitchIn.readLineNonwhiteChar();

// Convert character to unicode
Unicode = Character;

//Output result
System.out.println("You entered character " + Character + ".");
System.out.println("The Unicode value of Character " + Character + " is " + Unicode + ".");

}
}

Reply With Quote
  #2  
Old May 14th, 2004, 07:38 PM
Logwad Logwad is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 17 Logwad User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
well you could do

----------------------------------------------
if (Charactor.equalsIgnoreCase("a") ||
Charactor.equalsIgnoreCase("b") ||
Charactor.equalsIgnoreCase("c") ||
Charactor.equalsIgnoreCase("d") ||
...
Charactor.equalsIgnoreCase("z"))
{
// do nothing
}
else
{
system.out.println("you did something horribly wrong")
}
-----------------------------------------------

or something along those lines. (syntax may not be correct).

hope that helps. Feel free to ask more questions, though do not get disapointed if no one answers, i'm still waiting for someone to tell me about my problem -_-

Reply With Quote
  #3  
Old May 14th, 2004, 10:27 PM
Yellow_Chicken Yellow_Chicken is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 2 Yellow_Chicken User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thanks for the reply, but the code is going to be very long if I have to do it for every single character and digit. Is it possible to have the same result but typing less code?
thanks

Reply With Quote
  #4  
Old May 15th, 2004, 11:51 PM
singhnx singhnx is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Location: Chicago, IL
Posts: 9 singhnx User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Character testing

Try these methods from the Character class out...

Character.isLetter (char ch)
Character.isDigit (char ch)
Character.isLetterOrDigit (char ch)

These will return a boolean (true or false) and should get you what you want.

Have a good one.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingJava Development > Java newbie needs help


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway