Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Character.isUpperCase(char ch) function

807599Apr 28 2007 — edited Apr 28 2007
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.*;

public class Name
{
    public static void 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.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 26 2007
Added on Apr 28 2007
2 comments
629 views