2020 winter study notes 03

  Spark today to complete the installation is completed, more time is still on view on the postgraduate school, started Spark afternoon a second experiment, began to feel very simple, but later finished exercise2-1.scala file, did not know to how to run it, then ask a student to know but also to download and install scala, then I went to learn some of the basic grammar scala, and to the scala configured on Centos, just now, finally running out of the second the first title experiments, tomorrow will continue to understand the basic grammar and the Scala programming,

  Experimental reads as follows:

 

    Calculate the following series and outputting a sum of the first n Sn with programming scripts manner until just greater than or equal to the Sn q, wherein q is an integer greater than 0, the value through the keyboard:

    

    For example, if the q value is 50.0, the output should be: Sn = 50.416695.

    In the test run mode REPL, test samples: q = time 1, Sn = 2; q = 30 when, Sn = 30.891459; when q = 50, Sn = 50.416695.

  Source code is as follows:

 

 

 1 import io.StdIn._
 2 object Test {
 3     def main(args: Array[String]){
 4         var Sn:Float = 0
 5 
 6         var n:Float=1
 7 
 8     println("please input q:")
 9 
10     val q = readInt()
11 
12     while(Sn<q){
13         Sn+=(n+1)/n
14         n+=1
15     }
16 
17     println(s"Sn=$Sn")
18     }
19 }
20     
21 import io.StdIn._
22 object Test {
23     def main(args: Array[String]){
24         var Sn:Float = 0
25 
26         var n:Float=1
27 
28     println("please input q:")
29 
30     val q = readInt()
31 
32     while(Sn<q){
33         Sn+=(n+1)/n
34         n+=1
35     }
36 
37     println(s"Sn=$Sn")
38     }
39 }

Run results shown in Figure:

 

Guess you like

Origin www.cnblogs.com/qianmo123/p/12241529.html