2016-12-09 13 views
-2

System.out.println( "Angeföljande:");最初の文字を大文字にし、名前の行が空白の場合は "空にすることはできません"

System.out.print("Name: "); 
    String firstName = keyboard.nextLine(); 
    firstName = firstName.substring(0,1).toUpperCase() + firstName.substring(1).toLowerCase(); 

    while (firstName.equals("")) { 
     System.out.println("Name line can't be empty!!"); 
     System.out.print("Name: "); 
     firstName = keyboard.nextLine(); 
    } 
+0

あなたは問題が何であるかは言いませんでした。 – MalaKa

+0

おそらくindexoutofbounds – XtremeBaumer

+0

問題を説明してください。 –

答えて

0
System.out.print("Name: "); 
    String firstName = keyboard.nextLine(); 

    while (firstName.trim().equals("")) { 
     System.out.println("Name line can't be empty!!"); 
     System.out.print("Name: "); 
     firstName = keyboard.nextLine(); 
    } 
    firstName = firstName.substring(0, 1).toUpperCase() + firstName.substring(1).toLowerCase(); 
    System.out.println(firstName); 

移動あなたはしばらく後の最初の文字の上部ケースを作り、また作るためにあなたのwhile文でtrim()を使用するラインは必ずちょうどスペースが

+0

ありがとう!完璧に動作します! – Marcus

0

あなたは任意の文字列を置くことができるが入力されていません下のコードでAbcdの代わりに -

public static void main(String[] args) throws ParseException { 
    String check = "Abcd"; 
    if(check.isEmpty()){ 
     System.out.println("can't be empty..."); 
     System.exit(0); 
    } 
    char charAt = check.charAt(0); 
    if(Character.isUpperCase(charAt)){ 
     //do stuff condition satisfied 
    } 
} 
関連する問題