我如何 return 3 个字符串倒序?
How do I return 3 Strings in reverse order?
我正在使用java编程,用户已经输入了3个单词作为字符串,word1,word2,word 3。我的任务是首先将所有单词大写,例如:运行, roll, jump.....单词应该变成运行, ROLL, JUMP。问题是我必须对单词进行反向排序,例如:JUMP、ROLL、运行。我必须使用一个数组,对它们进行排序,然后 return 我该怎么做?这就是我的:
public static String reverseOrder(String word1, String word2, String word3) {
int a = word1.length();
int b = word2.length();
int c = word3.length();
String x;
String y;
String z;
x = word1.toUpperCase();
y = word2.toUpperCase();
z = word3.toUpperCase();
//this should be the output
String[] r = reverseOrder(word1,word2,word3);
System.out.println(Arrays.toString(r));
}
}
import java.util.Arrays;
class MyStringTest{
public static String[] reverseOrder(String word1, String word2,
String word3) {
// int a = word1.length();
// int b = word2.length();
// int c = word3.length();
// String x;
// String y;
// String z;
String x = word1.toUpperCase();
String y = word2.toUpperCase();
String z = word3.toUpperCase();
String[] r = new String[]{x, y, z};
// return the array
return r; // check the return type
}
public static void main(String [] args){
String [] r = reverseOrder("run", "roll", "jump");
System.out.println(Arrays.toString(r));
}
}
我正在使用java编程,用户已经输入了3个单词作为字符串,word1,word2,word 3。我的任务是首先将所有单词大写,例如:运行, roll, jump.....单词应该变成运行, ROLL, JUMP。问题是我必须对单词进行反向排序,例如:JUMP、ROLL、运行。我必须使用一个数组,对它们进行排序,然后 return 我该怎么做?这就是我的:
public static String reverseOrder(String word1, String word2, String word3) {
int a = word1.length();
int b = word2.length();
int c = word3.length();
String x;
String y;
String z;
x = word1.toUpperCase();
y = word2.toUpperCase();
z = word3.toUpperCase();
//this should be the output
String[] r = reverseOrder(word1,word2,word3);
System.out.println(Arrays.toString(r));
}
}
import java.util.Arrays;
class MyStringTest{
public static String[] reverseOrder(String word1, String word2,
String word3) {
// int a = word1.length();
// int b = word2.length();
// int c = word3.length();
// String x;
// String y;
// String z;
String x = word1.toUpperCase();
String y = word2.toUpperCase();
String z = word3.toUpperCase();
String[] r = new String[]{x, y, z};
// return the array
return r; // check the return type
}
public static void main(String [] args){
String [] r = reverseOrder("run", "roll", "jump");
System.out.println(Arrays.toString(r));
}
}