Doubt in display(id, name, salary) before display function

0 votes

Why is display(id, name, salary) mentioned before display function in the code provided below:

object example1 {

  def main(args:Array[String]) {

    val id = new Array[Int](5)

    println("Enter id")

    for (i <- 0 to 4) {

      id(i) = scala.io.StdIn.readInt()

    }

    val name = new Array[String](5)

    println("Enter name")

    for (i<-0 to 4){

    name(i) = scala.io.StdIn.readLine()

    }

  val salary = new Array[Int](5)

  println("Enter salary")

  for (i<-0 to 4){

    salary(i)= scala.io.StdIn.readInt()

  }

  display(id, name, salary)

   def display(id:Array[Int],name:Array[String],salary:Array[Int]) = {

     id.foreach(println)

     name.foreach(println)

     salary.foreach(println)

    }

  }

}
Jun 19 in Apache Spark by jenny
14 views

1 answer to this question.

0 votes

The statement display(id, name, salary) is written before the display function to call the display function. If we don't write that statement, the display function will not be called and it will not be executed. Also, while calling the display function we are passing the parameters: id, name, and salary.

answered Jun 19 by Ritu

Related Questions In Apache Spark

0 votes
1 answer

How to get ID of a map task in Spark?

you can access task information using TaskContext: import org.apache.spark.TaskContext sc.parallelize(Seq[Int](), ...READ MORE

answered Nov 20, 2018 in Apache Spark by Frankie
• 9,810 points
206 views
0 votes
1 answer

Sliding function in spark

The sliding function is used when you ...READ MORE

answered Jan 29 in Apache Spark by Omkar
• 67,120 points
125 views
0 votes
1 answer

How can we iterate any function using "foreach" function in scala?

Hi, Yes, "foreach" function you use because it will ...READ MORE

answered Jul 5 in Apache Spark by Gitika
• 19,720 points
21 views
0 votes
1 answer

Changing Column position in spark dataframe

Yes, you can reorder the dataframe elements. You need ...READ MORE

answered Apr 19, 2018 in Apache Spark by Ashish
• 2,630 points
3,432 views
0 votes
1 answer

Copy all files from local (Windows) to HDFS with Scala code

Please try the following Scala code: import org.apache.hadoop.conf.Configuration import ...READ MORE

answered May 22 in Apache Spark by Karan
37 views
0 votes
1 answer

Scala pass input data as arguments

Please refer to the below code as ...READ MORE

answered Jun 19 in Apache Spark by Lisa
22 views
0 votes
1 answer

How to calculate the result of formula with Scala?

Hi, You can use a simple mathematical calculation ...READ MORE

answered Jul 1 in Apache Spark by Gitika
• 19,720 points
27 views
0 votes
1 answer

How to execute a function in apache-scala?

Hi, Here is a simple example of how ...READ MORE

answered Jul 1 in Apache Spark by Gitika
• 19,720 points
23 views
+2 votes
4 answers

use length function in substring in spark

You can use the function expr val data ...READ MORE

answered May 3, 2018 in Apache Spark by kurt_cobain
• 9,240 points
9,757 views
0 votes
11 answers

How to create new column with function in Spark Dataframe?

val coder: (Int => String) = v ...READ MORE

answered Apr 4 in Apache Spark by anonymous

edited Apr 5 by Omkar 14,727 views