我需要從它刪除所有空格。如何刪除空間的字符串(句子)
如:這是我的代碼 O/P:Thisismycode
這是到目前爲止我的代碼。
import java.util.Scanner;
public class nospace{
public static void main(String args[]){
Scanner s=new Scanner(System.in);
System.out.println("Enter a String");
String N=s.nextLine();
N=N.trim();
N=N+" ";
int l=N.length();
int a=0;
for(int i=0;i<=l-1;i++){
if(N.charAt(i)==32){
System.out.println(N.substring(a,i+1));
}
a=i;
}
}
}
所有它打印每個單詞的最後一個字母。任何幫助表示讚賞。
可能重複【JAVA:從字符串中刪除字符的所有出現(http://stackoverflow.com/questions/4576352/java-remove-all-occurances-of-炭從串) – aruisdante