例如从String subjects={"语文","数学","英语","Java"};到String sub={"Java","英语","数学","语文"};怎么实现
import java.util.Scanner;
//循环从键盘录入4门学科名
public class Subjects {
public static void main(String[] args) {
//1.声明并分配了4个连续的空间,元素的初始值是null
String subjects[]=new String[4];
//2.循环7次录入学科名,存放到数组中
for (int i = 0; i < subjects.length; i++) {
//创建键盘录入
Scanner sc=new Scanner(System.in);
//3.提示用户录入学科名
System.out.println("请输入第"+(i+1)+"个学科的名字:");
//4.使用数组接收录入的数据
subjects[i]=sc.nextLine();
//Subjects[i]=sc.nextString();错误的写法,为什么错?
}
System.out.println("输入顺序"+"\t\t"+"科目");
//循环遍历查看数组的元素
for (int i= 0; i < subjects.length; i++) {
System.out.println((i+1)+"\t\t"+subjects[i]);
}
String str[]=new String[subjects.length];
for (int i= 0; i < subjects.length; i++) {
subjects[i-str.length]=str[i];
}
}
}