| 
 | 
 
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册  
 
x
 
假设在scores数组中保存了8名学生的成绩信息{33, 78, 27, 96, 76, 54, 92, 80},newScores数组内容为{34, 21, 44, 24, 56, 76, 54, 90, 87, 96, 76, 39}。现在需要将scores数组从第1个元素开始到结尾的所有元素复制到newScores的数组中,scores数组中的元素在newScores数组中从第2个元素开始排列,newScores数组新内容为{34, 21, 78, 27, 96, 76, 54, 92, 80, 96, 76, 39 }。(20分) 
题目内容: 
 
假设在scores数组中保存了8名学生的成绩信息{33, 78, 27, 96, 76, 54, 92, 80},newScores数组内容为{34, 21, 44, 24, 56, 76, 54, 90, 87, 96, 76, 39}。现在需要将scores数组从第1个元素开始到结尾的所有元素复制到newScores的数组中,scores数组中的元素在newScores数组中从第2个元素开始排列,newScores数组新内容为{34, 21, 78, 27, 96, 76, 54, 92, 80, 96, 76, 39 }。 
 
输入格式: 
 
-  for (int i = 0; i < scores.length; i++) {
 
  
-         scores[i] = scanner.nextInt();
 
  
- }
 
  
 
 
- for (int i = 0; i < newScores.length; i++) {
 
  
-         newScores[i] = scanner.nextInt();
 
  
- }
 
  复制代码 
 
输出格式: 
 
- for(int k=0; k < newScores.length; k++) {
 
  
-             System.out.print(newScores[k]+" ");
 
  
- }
 
  复制代码 
 
输入样例: 
 
33 78 27 96 76 54 92 80 
 
34 21 44 24 56 76 54 90 87 96 76 39 
 
输出样例: 
 
34 21 78 27 96 76 54 92 80 96 76 39  
 
-         package we;
 
 -         
 
 -         import java.util.Scanner;
 
 -         
 
 -         
 
 -                   
 
 -                 public class t1 {  
 
 -                     public static void main(String[] args) {  
 
 -                         Scanner scanner = new Scanner(System.in);  
 
 -                         int scores[] = new int[8];
 
 -                         int newScores[] = new int[12]; 
 
 -                         for (int i = 0; i < scores.length; i++) {
 
 -         
 
 -                                 scores[i] = scanner.nextInt();
 
 -         
 
 -                         }
 
 -                     
 
 -                         for (int i = 0; i < scores.length; i++) {  
 
 -                                  newScores[i]= scanner.nextInt();  
 
 -                         }  
 
 -                   
 
 -                         System.arraycopy(scores, 1, newScores, 2, 7);  
 
 -                   
 
 -                         for (int k = 0; k < newScores.length; k++) {  
 
 -                             System.out.print(newScores[k] + " ");  
 
 -                         }  
 
 -                     }  
 
 -                 }
 
 -         
 
 -         
 
 
  复制代码 
根据你的输入样例和输出样例,我重新整理了一下代码,希望能够满足你的需求:
 - import java.util.Scanner;
 - public class t1 {
 -     public static void main(String[] args) {
 -         Scanner scanner = new Scanner(System.in);
 -         
 -         int[] scores = new int[8];
 -         int[] newScores = new int[12];
 -         
 -         // 读取scores数组的成绩信息
 -         for (int i = 0; i < scores.length; i++) {
 -             scores[i] = scanner.nextInt();
 -         }
 -         
 -         // 读取newScores数组的初始内容
 -         for (int i = 0; i < newScores.length; i++) {
 -             newScores[i] = scanner.nextInt();
 -         }
 -         
 -         // 将scores数组从第一个元素开始复制到newScores数组的第二个元素位置
 -         System.arraycopy(scores, 0, newScores, 1, scores.length);
 -         
 -         // 输出newScores数组的内容
 -         for (int k = 0; k < newScores.length; k++) {
 -             System.out.print(newScores[k] + " ");
 -         }
 -     }
 - }
 
  复制代码
这样,你就可以按照你的输入样例,得到对应的输出结果。希望能够帮到你!如果还有其他问题,请随时提问。
 
以上回复来自 FishC AI 小助理,如未能正确解答您的问题,请继续追问。  
 
 
 |   
 
 
 
 |