【发布时间】:2015-01-07 21:17:41
【问题描述】:
我有一个类似
的字符串这是一个非常好的句子
我将它分成单独的单词并存储在String[] 中:
String[] words = s.split(" ");
我怎样才能对总词数(假设 2 个词,共 6 个词)取特定百分比,然后用其他词代替这 2 个词。到目前为止我的代码:
//Indexes in total
int maxIndex = words.length;
//Percentage of total indexes
double percentageOfIndexes = 0.20;
//Round the number of indexes
int NumOfIndexes = (int) Math.ceil( maxIndex * (percentageOfIndexes / 100.0));
//Get a random number from rounded indexes
int generatedIndex = random.nextInt(NumOfIndexes);`
【问题讨论】:
标签: android arrays string random words