You are on page 1of 4

Apka Guruji

This blog is dedicated to programmers, we post tutorials on computer programming.

Saturday, 9 February 2019

[Hindi] Introduction to StringTokenizer in java, count number of


words s...

[Hindi] Introduction to S…

Hello friends,  in this video we discuss the string tokenizer class and show you how you can write a
program in java to process a sentence and count number or words starting with capital letter using this
class, the video tutorial is useful for isc board computer science students as well as java programming
enthusiasts, engineering students and those who are preparing for some kind of programming
interviews.

Some useful links:

Basics of strings: https://www.youtube.com/watch?v=ytHnu-

3eDNQ&t=0s&list=PLgiXCk_tuNJv-Q9hleIzgQarGKZwT1x5u&index=159

isc java crash course: https://www.youtube.com/playlist?


list=PLgiXCk_tuNJtRVztF1bTsDeVCHYHSwuWH

isc students doubts: https://www.youtube.com/playlist?

list=PLgiXCk_tuNJu7rgWB0ThCqJa4FXr43GTe

icse java crash course: https://www.youtube.com/playlist?list=PLgiXCk_tuNJv-

Q9hleIzgQarGKZwT1x5u

icse students doubts: https://www.youtube.com/playlist?

list=PLgiXCk_tuNJsPnymc9S8FSKUokGlmrxqM

Source Code:

import java.util.*;

class CountWords

    private String s;

    private int c;

    public CountWords()

  {
        s = "";

        c = 0;

  }

    public void input()

  {

        Scanner sc = new Scanner(System.in);

        System.out.println("Enter the sentence: ");

        s = sc.nextLine();

  }

    public void compute()

  {

        StringTokenizer st = new StringTokenizer(s);

        String w;

        while(st.hasMoreTokens())

    {

            w = st.nextToken();

            if(Character.isUpperCase(w.charAt(0)))

                c++;

    }

  }

    public void display()

  {

        System.out.println("Number of such words: " + c);

  }

    public static void main(String args[])


  {

        CountWords ob = new CountWords();

        ob.input();

        ob.compute();

        ob.display();

  }

Apka Guruji at 06:17

Share

No comments:

Post a Comment

‹ Home ›
View web version

About Me

Apka Guruji
Follow 9

View my complete profile

Powered by Blogger.

You might also like