1

输入一行文本。请不要标点符号。

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)”读取字符“i”?正如建议的那样,我试图弄清楚剥离字母并将其与大写字母连接,但我不确定。

4

1 回答 1

1

“我”将是

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

换句话说,空格后面的字符。您当前正在输入输入字符串中的第一个字符。

于 2011-02-01T03:47:53.703 回答