类似于Java的ltrm()方法的程序 [英] program similar to ltrm() method of java

查看:268
本文介绍了类似于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());


这篇关于类似于Java的ltrm()方法的程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆