天天看點

Java數組連接配接并按從小到大輸出

1.用class1Grade數組儲存第一組資料,用class2Grade儲存第二組資料,每一組均是5個int型資料。

2.用gradeCount數組儲存合并後的數組,并将該數組元素按照從小到大的順序輸出

代碼如下;

下面展示一些

内聯代碼片

// A code block
var foo = 'bar';
           
// An highlighted block
package step2;
import java.util.Scanner;
import java.util.Arrays;
public class MarkStatistics {    
	public static void main(String[] args) 
	{        
	Scanner scanner = new Scanner(System.in);       
 	int[] class1Grade = new int[5];        
 	int[] class2Grade = new int[5];        
 	int[] gradeCount = new int[class1Grade.length + class2Grade.length];        
 	/********** Begin *********/            
 	for(int i=0;i<5;i++)            
 	{                
 		int s=scanner.nextInt();                
 		class1Grade[i]=s;            
 	}            
 	for(int i=0;i<5;i++)            
 	{                
 		int s=scanner.nextInt();                
 		class2Grade[i]=s;            
 	}
        System.arraycopy(class1Grade,0,gradeCount,0,class1Grade.length);            
        System.arraycopy(class2Grade,0,gradeCount,class1Grade.length,class2Grade.length);                
 	Arrays.sort(gradeCount);        
 	/********** End *********/        
 	for (int i = 0; i < gradeCount.length; i++) 
 	{            
 		System.out.print(gradeCount[i]);            
 		if (i != gradeCount.length - 1) 
 		{                
 			System.out.print(' ');            
 		}        
 	}    
     }
}