类似于Java的ltrm()方法的程序
问题描述:
import java.util.*;
class Ltrim
{
public static void main(String... S)
{
int count = 0;
char ch;
System.out.println("enter the line");
Scanner sc = new Scanner(System.in);
String Str = sc.nextLine();
for(int i=0;i<Str.length();i++)
{
ch = Str.charAt(i);
if(ch ==' ' && count == 0)
{
}
else
{
count = 1;
System.out.print(ch);
}
}
}
}
答
String strValue ="abcd efgh";
strValue = strValue.trim();
strValue = strValue.replaceAll(" ", "");
System.out.println("length " + strValue.length());