class TestStr
{
private String str;
TestStr(String str)
{
this.str=str;
}
public String mytrim()
{
String s;
int i=0;
int j=str.length()-1;
while(i<=j && str.charAt(i)==' ')
{
i++;
}
while(i<=j && str.charAt(j)==' ')
{
j--;
}
s=str.substring(i,j+1);
return s;
}
}
class TestString
{
public static void main(String[] args)
{
TestStr str=new TestStr(" helle java! ");
String t=str.mytrim();
System.out.println(t);
}
}
|