java - a method that recieves String input and divides it into 1,2 and 3 different sections -
java - a method that recieves String input and divides it into 1,2 and 3 different sections -
i need more basic method! split words 1,2,3 consecutive compartments, output "water" should in terms of array string! e.g input of water should produce output {"w","a","t","e","r","wa","at","te","er","wat","ate","ter"}
public void split(string word) { int x=(word.length())/2; int z=word.length(); string[] partition= new string[5]; (int i=0; i<x; i++){ string new1=character.tostring(word.charat(i)); string new2 = character.tostring(word.charat(i))+character.tostring(word.charat(i+1)); string new3 = character.tostring(word.charat(i))+character.tostring(word.charat(i+1))+character.tostring(word.charat(i+2)); string new4 = removeduplicate(character.tostring(word.charat(z-2))+ character.tostring(word.charat(z-1))); string new5 = removeduplicate(character.tostring(word.charat(z-3))+ character.tostring(word.charat(z-2))+ character.tostring(word.charat(z-1))); char result = word.charat(2); string[] partitions = {new1,new5,new3,new4,new2}; //partition=partitions; //arrays.tostring((removeduplicates(partitions))) system.out.println(partitions); } //return partition; }
here illustration how can that. hope if not beginner know arraylist
.
string word = "water"; arraylist<string> list = new arraylist<string>(); (int = 1; <= 3; i++) { int limit = word.length() - + 1; (int j = 0; j < limit; j++) { list.add(word.substring(j, j+i)); } } system.out.println(list);
output :
[w, a, t, e, r, wa, at, te, er, wat, ate, ter]
try understand it. , tell me if having doubt.
java
Comments
Post a Comment