Monday, August 20, 2012

How to count word in string using java



Output:
Number of words are: 6

CountWords.java

package com.swain.cell;

import java.util.StringTokenizer;

public class CountWords {

       /**
        * @param args
        */
       public static void main(String[] args) {
              // TODO Auto-generated method stub
        String st="how to count word in java?";
        int count=0;
        StringTokenizer stk=new StringTokenizer(st," ");
        while(stk.hasMoreTokens()){
            String token=stk.nextToken();
            count++;
        }
        System.out.println("Number of words are: "+count);

       }

}

How to Calculate the Future Investment Value of Investment.

Below java program for calculate future investment value. Here calculate s using the formula futureInvestmentValue =investmentAmount x (...