Character.isUpperCase(char ch) function

Hello,

i am programming a code and have a method which asks the user to enter their first name. Then i need the method checks if the first letter is capitals A to Z, if not it displays an error message. But, i cannot seem to get it working. Someone told me than Java does not use the ascII code so use the Character(char ch) to check if it is uppercase, if not reply with an error message. but doesn't that check every letter is uppercase. I also only want the user to enter only one name, ie 1 word, how would i go about doing that. my code is:

import java.util.*;

publicclass Name

{

publicstaticvoid main (String[] args)

{

Scanner console =new Scanner(System.in);

// Variables

String name="";

// Input of first name

System.out.print("Please enter first name: ");

name = console.nextLine();

while((Character.UpperCase(1) ==false)||(/*test for one word goes here*/ ))

{

// Test for uppercase

if(Character.isUpperCase(1) ==false)

{

System.out.print("Error! First name must start with a capitil letter.");

System.out.print("Please enter first name again: ");

name = console.nextLine();

}

// Test for one word

if(/*test for one word goes here*/ )

{

System.out.print("Error! First name can only be one word");

System.out.print("Please enter first name again: ");

name = console.nextLine();

}

}

}

}

Thankyou for your help.

[2526 byte] By [wat_unavailablea] at [2007-11-27 2:41:17]
# 1

> while((Character.UpperCase(1) == false)||( /*test for one word goes here*/ ))

What is this UpperCase() method?

You'll be better off using methods from the Character class (http://java.sun.com/javase/6/docs/api/java/lang/Character.html). You are looking for a method that checks whether a given char value is upper case.

Of course, this depends on being able to get the first letter of a String as a char value. The String class is documented here: http://java.sun.com/javase/6/docs/api/java/lang/String.html Look for a method to find the char at a given position. (Then test that char to see if it is upper case).

A String represents a single word if it does not contain a space.

pbrockway2a at 2007-7-12 3:04:56 > top of Java-index,Java Essentials,New To Java...
# 2
Hi, unavailableYou should use string tokenizer and charAt (0),and I think your class should be private static boolean in CalInterface, and methods getName and set name public in Client class.Hope this helpsRJ
RavenJavena at 2007-7-12 3:04:56 > top of Java-index,Java Essentials,New To Java...