Click here to Skip to main content
15,887,444 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
import java.util.*;
class Squeeze
{
    public static void main(String... s)
    {
        Scanner sc = new Scanner(System.in);
        System.out.println("enter a paragraph");
        String Str = sc.nextLine();
        for(int i=0;i<Str.length();i++)
        {
            char ch = Str.charAt(i);
            if(ch ==' ')
            {}
            else
            {
                System.out.print(ch);
            }
        }
    }
}
Posted
Updated 2-Apr-12 22:25pm
v3
Comments
ZurdoDev 2-Apr-12 11:31am    
Is there a question somewhere?
nikhil_kumar 2-Apr-12 16:41pm    
i want to make code small means optimize the code.....
TorstenH. 3-Apr-12 3:53am    
I added a homework tag - cause that's what this is.

1 solution

Here[^] are some methods that will help you.
 
Share this answer
 
Comments
nikhil_kumar 2-Apr-12 16:40pm    
thnx for help me.......
TorstenH. 3-Apr-12 3:55am    
you need to exchange the spaces against a non existing space -> the String for that is written "" .
String.replaceAll(String strSearchfor, String strReplacement) is a really nice option.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900