Array-promo

Question

program to remove white spaces from a sentence.

Share code with your friends

Share on whatsapp
Share on facebook
Share on twitter
Share on telegram

Code

				
					
import java.util.Scanner;
public class printWhiteSpacesFromSentence 
{  
    public static void main(String[] args)
    {  
        String sen="",sen1="";
        char ch=' ';
        int i=0,len=0;
        Scanner sc = new Scanner(System.in);    
        
        System.out.println("Enter a sentence");   
        sen = sc.nextLine(); 
        sen=sen;
        System.out.println("Sentences with white space:"+sen);

        len=sen.length();
        for(i=0;i< len;i++)
        {
            ch=sen.charAt(i);
            if(ch!=' ')
            {
                sen1=sen1+ch;
            }
        }
        System.out.println("Sentences without white space:"+sen1);
    }  
}    

				
			

Coding Store

Leave a Reply

Your email address will not be published. Required fields are marked *