public class ReplaceOneAndPrint {
static String testcase="ABC ";
public static void main(String args[]){
ReplaceOneAndPrint testInstance=new ReplaceOneAndPrint();
String result=testInstance.checkString(testcase);
System.out.println(result);
}
public String checkString(String str){
String holdReplaceFormat=str;//store the max occurence of char in string
String newString="";
String oneWhiteSpace=" ";
char holdEachChar=' ';//hold each char of the string
int i=0;
int lenStr=str.length();
int lenholdReplaceFormat=0;
while(lenStr>0){//check the string len coz each time the string getting shorter
holdEachChar=holdReplaceFormat.charAt(i);//hold the first char of string each time
holdReplaceFormat=holdReplaceFormat.substring(i+1);
newString = newString+oneWhiteSpace+holdReplaceFormat;
System.out.println(newString);
lenholdReplaceFormat=holdReplaceFormat.length();
lenStr=lenholdReplaceFormat;
System.out.println("lenStr issss:"+lenStr);
if(lenStr==1){
break;
}
}
newString=str+newString;
return newString;
}
}
static String testcase="ABC ";
public static void main(String args[]){
ReplaceOneAndPrint testInstance=new ReplaceOneAndPrint();
String result=testInstance.checkString(testcase);
System.out.println(result);
}
public String checkString(String str){
String holdReplaceFormat=str;//store the max occurence of char in string
String newString="";
String oneWhiteSpace=" ";
char holdEachChar=' ';//hold each char of the string
int i=0;
int lenStr=str.length();
int lenholdReplaceFormat=0;
while(lenStr>0){//check the string len coz each time the string getting shorter
holdEachChar=holdReplaceFormat.charAt(i);//hold the first char of string each time
holdReplaceFormat=holdReplaceFormat.substring(i+1);
newString = newString+oneWhiteSpace+holdReplaceFormat;
System.out.println(newString);
lenholdReplaceFormat=holdReplaceFormat.length();
lenStr=lenholdReplaceFormat;
System.out.println("lenStr issss:"+lenStr);
if(lenStr==1){
break;
}
}
newString=str+newString;
return newString;
}
}
No comments:
Post a Comment