关于while循环 or for循环 跟arrays的互换。。
两个arrays Strings:String[] quoteOne = {"Facts","are","the","enemy","of","truth"};
String[] quoteTwo = {"Glory","is","fleeting","Obscurity","is","forever"};
怎么样用while循环 或 for 循环把String[] quoteOne & String[] quoteTwo里面的元素调换,例如quoteOne[0] 包含String
"Glory", quoteTwo[0]包含String“facts”, quoteOne[1]包含String"is", quoteTwo[1]包含String"are"等等。。谢谢。
搜索更多相关的解决方案:
arrays
----------------解决方案--------------------------------------------------------
class check
{
public static void main(String[] agrs)
{
String[] array = {"Facts","are","the","enemy","of","truth"};
String[] array1 = {"Glory","is","fleeting","Obscurity","is","forever"};
int number = 0;
String str = "";
while(number <= array.length-1)
{
str = array[number];
array[number] = array1[number];
array1[number] = str;
number++;
}
}
}
----------------解决方案--------------------------------------------------------
用一个中间的变量,用于暂时存储一方的字符就可以了.这和排序中的冒泡算法类似
----------------解决方案--------------------------------------------------------
谢谢大家~
----------------解决方案--------------------------------------------------------