title: Word count using Spark and Scala
body: <p>i have to write a program in Scala, using spark which counts how many times a word occours in a text, but using the RDD my variable count always displays 0 at the end. Can you help me please?
  This is my code</p>
  
  <pre><code>import scala.io.Source
  import org.apache.spark.SparkContext
  import org.apache.spark.SparkContext._
  import org.apache.spark.SparkConf
  
  object wordcount {
      def main(args: Array[String]) {
        // set spark context
        val conf = new SparkConf().setAppName("wordcount").setMaster("local[*]")
        val sc = new SparkContext(conf)
  
        val distFile = sc.textFile("bible.txt")
  
        print("Enter word to loook for in the HOLY BILE: ")
        val word = Console.readLine
        var count = 0;
        println("You entered " + word)
  
        for (bib &lt;- distFile.flatMap(_.split(" "))) {
  
          if (word==bib) {
              count += 1
  
          }
  
        }  
        println(word + " occours " + count + " times in the HOLY BIBLE!")
      }
  }
  </code></pre>