Full Range

Call me (USA Free)

Monday 14 April 2014

String programs.....

1 comment
Q.Write a java program to count the number of words in the entered sentence

 import java.io.*;
public class CountWords
{
  public static void main(String args[])throws Exception
    {
       BufferedReader stdin =new BufferedReader(new InputStreamReader(System.in));
       System.out.print("Enter the sentence: ");
       String s=stdin.readLine();
       s=' '+s;
       char ch;
       int w=0;
       for(int i=0;i<s.length();i++) //loop is used to extract each character in the sentence
        {
           ch=s.charAt(i);
           if(ch==' ')
            {
             w++;
            }
        }
     System.out.println("Number of word in the sentence:"+w);
    } //method
} //class


Q.Write a program to accept a word and  arrange the letters of words in alphabetical order
    Sample input: computer
                output:cemoprtu

import java.io.*;
public class WordAlbha
 {
     public static void main(String args[])throws Exception
     {
         InputStreamReader isr =new InputStreamReader(System.in);
         BufferedReader stdin=new BufferedReader(isr);
         System.out.print("Enter the word:");
         String word=stdin.readLine();
         char ch;
         for(int i=65;i<=90;i++)
          {
              for(int j=0;j<word.length();j++)
               {
                   ch=word.charAt(j);
                   ch=Character.toLowerCase(ch);
                   if(ch==(char)i||ch==(char)(i+32))
                   System.out.print(ch);
                }
           }
        }
    }    

If You Enjoyed This, Take 5 Seconds To Share It

1 comment:

  1. WynnBET : Situs Slot Online | Casino Online Gambling
    WynnBET - 나비효과 Situs Slot Online WynnBet - Situs Slot https://access777.com/ Online WynnBet - gri-go.com Situs Slot herzamanindir.com/ Online WynnBet - Situs Slot Online WynnBet - Situs Slot deccasino Online WynnBet - Situs Slot Online

    ReplyDelete