Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > BOOK: Ivor Horton's Beginning Java, Java 7 Edition
| 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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old May 1st, 2012, 05: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");
				}
			}
		}
	}
}


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 09:29 AM
BIND attribute (page 83) Stephan_GER BOOK: Professional ASP.NET MVC 2 2 September 7th, 2010 12:40 PM
Checking Previous Page shs BOOK: Beginning ASP.NET 1.0 2 September 23rd, 2004 11:01 PM
Checking page size in kb G Classic ASP Basics 1 September 24th, 2003 02:47 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.