2 strings
unknown
java
2 years ago
1.8 kB
8
Indexable
public class TestMain1 { public static void main(String[] args) { String input1 = "WIPRO"; String input2 = "TECHNOLOGIES"; String[][] res = new String[2][3]; String[] words = {input1, input2}; // Note : index starts with 0. for (int i = 0; i < 2; i++) { // iterate 2 words int length = words[i].length(); // as 2 words we have [2] in 0th index we will store the 1st word and in 1th index store the 2nd word // content of 1st array // as 3 parts so we have [3] and split and store the words here if (length % 3 == 0 || length % 3 == 1) { res[i][0] = words[i].substring(0, length / 3); res[i][1] = words[i].substring(length / 3, length - length / 3); res[i][2] = words[i].substring(length - length / 3); } else { res[i][0] = words[i].substring(0, length / 3 + 1); res[i][1] = words[i].substring(length / 3 + 1, length - length / 3 - 1); res[i][2] = words[i].substring(length - length / 3 - 1); } } // as per output contents given in program // 1st part of word 2.. so in [2][3] word 2 is stored in 1st index and 1s part so 0th index.. so [1][0] // 1st part of word 1 .. so in [2][3] word 1 is stored in 0th index and 1st part so 0th index so [0][0] // 3rd part of word 1 .. so in [2][3] word 1 is stored in 0th index and 3rd part so 2th index so [0][2] // 3rd part of word 2 .. so in [2][3] word 2 is stored in 1th index and 3rd part so 2th index so [1][2] System.out.println(res[1][0] + res[0][0] + res[0][2] + res[1][2]); } }
Editor is loading...