- public class Shuzu {
- public static void main(String[] args) {
- System.out.println("请输入数据 , 以over结束,请输入少于1024个数组");
- String str[] = Num();
- Copy(str, 0, 3);
- Nixu(str);
-
- Array(str);
- }
- public static String[] Copy(String strr[], int start, int end) {
- String copystr[] = new String[end - start];
- for (int i = 0; i < end - start; i++) {
- copystr[i] = strr[start];
- }
- return copystr;
- }
- public static String[] Num() {
- String strr1[] = new String[1024];
- int i = 0;
- while (true) {
- Scanner sc = new Scanner(System.in);
- String str = sc.next();
- if (str.equals("over")) {
- sc.close();
- break;
- } else {
- strr1[i] = str;
- i++;
- }
- }
- String strr[] = new String[i];
- for (int j = 0; j < i; j++) {
- strr[j] = strr1[i];
- }
- return strr;
- }
- public static String[] Nixu(String str[]) {
- String[] strr = new String[str.length];
- for (int i = 0; i < str.length; i++)
- strr[i] = str[str.length - 1 - i];
- return strr;
- }
- public static String[] Array(String str[]) {
- String strr = "";
- for (int i = 1; i < str.length; i++) {
- if (str[i - 1].compareTo(str[i]) > 0) {
- strr = str[i];
- str[i] = str[i - 1];
- str[i - 1] = strr;
- }
- }
- return str;
- }
- }
复制代码 空指针异常,请问为什么?? |
|