In this program user will enter any sentence with number of blank
spaces. All the blank spaces will be removed and the sentence will be displayed
as one segment. Number of blank spaces removed will also be displayed.
Sample input:- BlueJ String
class program on removing blank spaces
Sample output:- BlueJStringclassprogramonremovingblankspaces
blank spaces deleted =7
import java.io.*;
class Sen
{
String str;
int i,len,sp=0;
char ch;
BufferedReader br=new BufferedReader(new
InputStreamReader(System.in));
void take() throws Exception
{
System.out.println("Enter the sentence: ");
str=br.readLine();
len=str.length();
for(i=0;i< len;i++)
{
ch=str.charAt(i);
if(ch==' ')
sp++;
else
System.out.print(ch);
}
System.out.print("
Number of spaces removed:"+sp);
}
public static void
main(String args[])throws Exception
{
Sen tr=new Sen ();
tr.take();
}
}
No comments:
Post a Comment