Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Java > Java and JDK > BOOK: Ivor Horton's Beginning Java, Java 7 Edition
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Ivor Horton's Beginning Java, Java 7 Edition
This is the forum to discuss the Wrox book Ivor Horton's Beginning Java, Java 7 Edition by Ivor Horton ; ISBN: 978-0-470-40414-0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Ivor Horton's Beginning Java, Java 7 Edition section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old May 1st, 2012, 06:39 AM
Registered User
Points: 31, Level: 1
Points: 31, Level: 1 Points: 31, Level: 1 Points: 31, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2012
Location: Mumbai,India
Posts: 9
Thanks: 0
Thanked 2 Times in 2 Posts
Thumbs up [Page 83] Checking whether the character is Digit/Letter/Whitespace

Code:
import static java.lang.Character.*; //Importing ALL the methods from Character class
import static java.lang.Math.random; //Importing the method random() from Math class
public class AlphaMethods {
	public static void main(String[] args)
	{
		char alpha=(char)(128*random()); 	//Used to generate a random number and cast it into char
		System.out.println("The Generated char is: " + alpha);	//To print the generated character and for manual verification
		
		if(isLetter(alpha)) {
			if(isUpperCase(alpha)) {
				System.out.println("Upper Case Alphabet");
			}
			else {
				System.out.println("Lower Case Alphabet");
			}
		}
		else {
			if(isDigit(alpha)) {
				System.out.println("Digit");
			}
			else {
				if(isWhitespace(alpha)) {
					System.out.println("White Space");
				}
				else {
					System.out.println("Symbol");
				}
			}
		}
	}
}
Reply With Quote
Reply


Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Working with Strings Function Try It Out page : 83 nawar youssef BOOK: Beginning PHP 5.3 1 September 11th, 2011 10:29 AM
BIND attribute (page 83) Stephan_GER BOOK: Professional ASP.NET MVC 2 2 September 7th, 2010 01:40 PM
Checking Previous Page shs BOOK: Beginning ASP.NET 1.0 2 September 24th, 2004 12:01 AM
Checking page size in kb G Classic ASP Basics 1 September 24th, 2003 03:47 AM



All times are GMT -4. The time now is 01:45 PM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.