我有一个字符串作为输入,我想将整个字符串转换为小写字母,除了一个需要大写的随机字母。
我尝试过以下方法: splited是输入字符串数组
Translated:
我有一个字符串作为输入,我想将整个字符串转换为小写字母,除了一个需要大写的随机字母。
我尝试过以下方法:splited是输入字符串数组
word1 = splited[0].length();
word2 = splited[1].length();
word3 = splited[2].length();
int first = (int) Math.random() * word1;
String firstLetter = splited[0].substring((int) first, (int) first + 1);
String lowcase1 = splited[0].toLowerCase();
char[] c1 = lowcase1.toCharArray();
c1[first] = Character.toUpperCase(c1[first]);
String value = String.valueOf(c1);
System.out.println(value);
当我尝试打印该字符串时,它总是返回第一个字母大写,其余部分为小写。为什么它不返回随机字母而是第一个字母呢?祝好!
word1
的值是多少? - Matt BallMath.random() * range
。 - user3353723word1
的值为6
,因为字符串是“author”。 - user3353723