JavaAlgorithms/countwords.java
zacharyjones123 03dbfa78c8 - Closed all Scanner and Buffered Readers
- Added Some Java Doc

- ReverseString - took space out of between each letter so "Zachary" to
"yrahcaZ" instead of "y r a h c aZ"

- bfs - Trying to repair this class but need to research bfs more

- dfs - Trying to repair this class but need to research dfs more

- Added new Classes
1) OctalToBinary - Not done
2) BinaryToOctal - Not done
3) OctalToDecimal - Not done
4) Graphs

-Added the dataStructure Graphs (Unfinished)
2017-04-20 11:56:21 -07:00

33 lines
746 B
Java

import java.util.Scanner;
/**
* You enter a string into this program, and it will return how
* many words were in that particular string
*
* @author Unknown
*
*/
class CountTheWords
{
/**
* The main method
*
* @param args Command line arguments
*/
public static void main(String args[])
{
System.out.println("Enter the string");
Scanner sc = new Scanner(System.in);
String s=sc.nextLine();
int count = 1;
for (int i = 0; i < s.length()-1; i++)
{
if((s.charAt(i) == ' ') && (s.charAt(i+1) != ' '))
{
count++;
}
}
System.out.println("Number of words in the string = "+count);
sc.close();
}
}