欧美亚洲中文,在线国自产视频,欧洲一区在线观看视频,亚洲综合中文字幕在线观看

      1. <dfn id="rfwes"></dfn>
          <object id="rfwes"></object>
        1. 站長資訊網(wǎng)
          最全最豐富的資訊網(wǎng)站

          java如何實現(xiàn)多數(shù)組合并

          java如何實現(xiàn)多數(shù)組合并

          需求:

          現(xiàn)在有多組整數(shù)數(shù)組,需要將他們合并成一個新的數(shù)組。

          (推薦教程:java入門教程)

          合并規(guī)則:

          從每個數(shù)組里按順序取出固定長度的內(nèi)容合并到新的數(shù)組中,取完的內(nèi)容會刪除掉,如果該行不足固定長度或者已經(jīng)為空,則直接取出剩余部分的內(nèi)容放到新的數(shù)組中,繼續(xù)下一行。

          (視頻教程推薦:java視頻教程)

          代碼實現(xiàn):

          package Shuru_lianxi;   import java.util.ArrayList; import java.util.Scanner;   public class biShi {   	public static boolean isNull(ArrayList<String> gh) { 		int i = 0; 		for (i = 0; i < gh.size(); i++) { 			if (gh.get(i) != null) 				break; 		} 		if (i < gh.size()) { 			return false; 		} else { 			return true; 		} 	}   	public static void Alg(ArrayList<String> ma, int num) { 		String tem = "";// 作為最后的返回結(jié)果 		while (!isNull(ma)) { 			for (int i = 0; i < ma.size(); i++) { 				String sk = ma.get(i); 				if (sk == null) { 					continue; 				} 				String[] gg = sk.split(","); 				if (sk.length() == 0) { 					ma.set(i, null);// 刪掉取完的內(nèi)容 				} else { 					if (gg.length <= num) { 						tem = tem + sk + ","; 						ma.set(i, null); 					} else { 						for (int k = 0; k < num; k++) { 							tem = tem + gg[k] + ","; 						} 						String hh = ""; 						for (int l = num; l < gg.length; l++) { 							if (l == gg.length - 1) { 								hh = hh + gg[l]; 							} else { 								hh = hh + gg[l] + ","; 							} 						} 						// 將沒取完的數(shù)組重新覆蓋 						ma.set(i, hh); 					} 				} 			} 		} 		System.out.println(tem.substring(0, tem.length() - 1)); 	}   	public static void main(String[] args) { 		Scanner sc = new Scanner(System.in); 		int num = sc.nextInt(); 		ArrayList<String> ma = new ArrayList<String>(); 		sc.nextLine();// nextInt()會留下一個回車,需要消除,否則后邊會出錯 		while (!sc.hasNext("#")) {// 以#結(jié)束,這里你可以修改成其他的 			ma.add(sc.nextLine()); 		} 		Alg(ma, num); 	} }

          贊(0)
          分享到: 更多 (0)
          網(wǎng)站地圖   滬ICP備18035694號-2    滬公網(wǎng)安備31011702889846號