2011-02-01 33 views
1

輸入一行文字。沒有標點符號。Java-toUpperCase一個字母

Java是語言。

我已經改寫上面一行改爲:

是語言的Java。

嘗試:

int x; 
String sentence, first; 

System.out.println("\nEnter a line of text. No punctuation please."); 

Scanner keyboard = new Scanner (System.in); 

sentence=keyboard.nextLine(); 

    x = sentence.indexOf(" "); 
first= sentence.substring(0,x); 
second=sentence.substring(0,1) 
second=second.toUpperCase(); 
System.out.println("I have rephrased that line to read:"); 
System.out.println(second+sentence.substring(x+1)+" "+first); 

輸出:

輸入一行文本。沒有標點符號。

是怎麼回事

我已經改寫上面一行改爲://它應該閱讀「是怎麼回事什麼」

W¯¯回事什麼

PS -I需要做信「我」資本。我怎樣才能讓「second.substring(0,1)」讀字符「我」?正如所暗示的那樣,我試圖弄清楚剝離字母並用大寫字母連接它,但我不確定。

回答

1

「我」 將是

second=sentence.substring(x+1,x+2); 

換句話說,在空格後的字符。您當前正在輸入字符串中的第一個字符。

+0

非常感謝。 – jay 2011-02-01 04:13:27

相關問題