Create a program that contains a String that holds your favo
Create a program that contains a String that holds your favorite movie quote and display the total number of spaces contained in the String. Save the file as CountMovieSpaces.java.
Solution
CountMovieSpaces.java
public class CountMovieSpaces {
public static void main(String[] args) {
String quote = \"Greed, for lack of a better word, is good.\";
int countSpaces = 0;
for(int i=0; i<quote.length(); i++){
if(quote.charAt(i) == \' \'){
countSpaces++;
}
}
System.out.println(\"The number of spaces contained in movie quote is: \"+countSpaces);
}
}
Output:
The number of spaces contained in movie quote is: 8
