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

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 Co

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site