import java.io.*; import java.util.*; public class ArraySort { public static void main(String[] args) { StringBuilder sb= new StringBuilder(); List<String> listStr = new ArrayList<String>(); String[] sourceWord = {"this", "fat", "two", "that", "fuck", "oaw"}; String[][] sourceStr = {{"t", "h", "i","s"}, {"w", "a", "t", "s"}, {"o", "a", "h", "g"}, {"f", "g", "d", "t"}, {"g", "o", "a", "w"}}; for(int i = 0; i < sourceStr.length; i++){ for(int j = 0; j < sourceStr[i].length; j++) { sb.append(sourceStr[i][j]); } String sbStr = sb.toString(); for (int k = 0; k < sourceWord.length; k++) { if (sb.indexOf(sourceWord[k]) != -1) { System.out.println(sourceWord[k] + " at line " + (i+1) + " and index of " + (sb.indexOf(sourceWord[k])+1)); } } sb.setLength(0); } for(int i = 0; i < sourceStr[i].length; i++){ String [] singleSourceStr = sourceStr[i]; for(int j = 0; j < sourceStr.length; j++) { sb.append(sourceStr[j][i]); } String sbStr = sb.toString(); for (int k = 0; k < sourceWord.length; k++) { if (sb.indexOf(sourceWord[k]) != -1) { System.out.println(sourceWord[k] + " at line " + (i+1) + " and index of " + (sb.indexOf(sourceWord[k])+1)); } } sb.setLength(0); } String[] oneArray = new String [sourceStr.length * sourceStr[0].length]; for(int i = 0; i < sourceStr.length; i++){ String [] singleSourceStr = sourceStr[i]; for(int j = 0; j < singleSourceStr.length; j++) { oneArray[i * 4 + j] = sourceStr[i][j]; } } for(int i = 0; i < oneArray.length; i++){ int startInt = i + sourceStr.length + 1; if (startInt < oneArray.length) { for (int j = 0 ; j < startInt ; j++) { for (int k = j; k < j + (sourceStr[0].length - (j % sourceStr[0].length) - (j / sourceStr[0].length)) * (sourceStr[0].length + 1); k += sourceStr[0].length + 1) { //System.out.print(k + " ,"); sb.append(oneArray[k]); } listStr.add(sb.toString()); sb.setLength(0); } } } System.out.println(listStr); for (int i = 0; i < sourceStr.length; i++) { for (int j = 0; j < sourceStr[i].length ; j += 1) { System.out.print(sourceStr[i][j] + " "); } System.out.println(); } } }
时间: 2024-10-15 20:07:03