How to removed White space in Given String|| Write a program to removed the space by er prince kumar
Write a program to removed all the white space in String
======================================================================
import java.util.*;
class RemovedSpaceFromString
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
System.out.print("Input:");
String s=sc.nextLine();
String s1="";
for(int i=0;i<s.length();i++){
if(s.charAt(i)!=' '){
s1=s1+s.charAt(i);
}
}
s=s1;
System.out.println("Output:"+s);
System.out.println();
}
}
Output:
Comments
Post a Comment