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.