确定首先我想说我是Java Development的新手... 考虑到这一点,我正在尝试使tryWord的值包含空格而不是在s空间的情况下破折号。谁能帮我?在空间的情况下包含空格而不是破折号
String tryWord = "";
for (int i = 0; i < s.length(); i++) {
tryWord += "-";
}
System.out.println(s + tryWord);
Value for s
------------
private static String randomOutput() {
String array[] = new String[10];
array[0] = "Hamlet";
array[1] = "Mysts of Avalon";
array[2] = "The Iliad";
array[3] = "Tales from Edger Allan Poe";
array[4] = "The Children of Hurin";
array[5] = "The Red Badge of Courage";
array[6] = "Of Mice and Men";
array[7] = "Utopia";
array[8] = "Chariots of the Gods";
array[9] = "a Brief History of Time";
ArrayList<String> list = new ArrayList<String>(Arrays.asList(array));
Collections.shuffle(list);
String s = list.get(0);
return s;
}
你并不需要复制一个列表洗牌它,你不需要重新洗牌列表中得到一个元素。你可以得到一个没有这些数组的随机元素。 – 2013-04-24 14:01:23
你希望tryWord在循环结束时有什么价值? – anubhava 2013-04-24 14:07:17