From e9f97b64fa92cd5481f4eb45a2dd01ca25ac008d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=E5=98=89=E9=98=B3?= Date: Sun, 25 Nov 2018 20:27:31 +0800 Subject: [PATCH] =?UTF-8?q?=E5=87=BD=E6=95=B0=E8=AF=AD=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 41 +++++++++++ pom.xml | 73 +++++++++++++++++++ src/main/scala/top/fjy8018/App.scala | 15 ++++ .../scala/top/fjy8018/scala/FunctionApp.scala | 32 ++++++++ .../scala/top/fjy8018/scala/HelloWorld.scala | 7 ++ 5 files changed, 168 insertions(+) create mode 100644 .gitignore create mode 100644 pom.xml create mode 100644 src/main/scala/top/fjy8018/App.scala create mode 100644 src/main/scala/top/fjy8018/scala/FunctionApp.scala create mode 100644 src/main/scala/top/fjy8018/scala/HelloWorld.scala diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3de72ce --- /dev/null +++ b/.gitignore @@ -0,0 +1,41 @@ +# use glob syntax. +syntax: glob +*.ser +*.class +*~ +*.bak +#*.off +*.old + +# eclipse conf file +.settings +.classpath +.project +.manager +.scala_dependencies + +# idea +.idea +*.iml + +# building +target +build +null +tmp* +temp* +dist +test-output +build.log + +# other scm +.svn +.CVS +.hg* + +# switch to regexp syntax. +# syntax: regexp +# ^\.pc/ + +#SHITTY output not in target directory +build.log diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..d23abab --- /dev/null +++ b/pom.xml @@ -0,0 +1,73 @@ + + 4.0.0 + top.fjy8018 + helloscala + 1.0-SNAPSHOT + ${project.artifactId} + My wonderfull scala app + 2010 + + + My License + http://.... + repo + + + + + 1.8 + 1.8 + UTF-8 + 2.11.8 + + + + + org.scala-lang + scala-library + ${scala.version} + + + + + src/main/scala + src/test/scala + + + org.scala-tools + maven-scala-plugin + 2.15.0 + + + + compile + testCompile + + + + -make:transitive + -dependencyfile + ${project.build.directory}/.scala_dependencies + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.6 + + false + true + + + + **/*Test.* + **/*Suite.* + + + + + + diff --git a/src/main/scala/top/fjy8018/App.scala b/src/main/scala/top/fjy8018/App.scala new file mode 100644 index 0000000..19ce390 --- /dev/null +++ b/src/main/scala/top/fjy8018/App.scala @@ -0,0 +1,15 @@ +package top.fjy8018 + +/** + * @author ${user.name} + */ +object App { + + def foo(x : Array[String]) = x.foldLeft("")((a,b) => a + b) + + def main(args : Array[String]) { + println( "Hello World!" ) + println("concat arguments = " + foo(args)) + } + +} diff --git a/src/main/scala/top/fjy8018/scala/FunctionApp.scala b/src/main/scala/top/fjy8018/scala/FunctionApp.scala new file mode 100644 index 0000000..bd7cf41 --- /dev/null +++ b/src/main/scala/top/fjy8018/scala/FunctionApp.scala @@ -0,0 +1,32 @@ +package top.fjy8018.scala + +/** + * F嘉阳 + * 2018-11-25 20:21 + */ +object FunctionApp { + def main(args: Array[String]): Unit = { + println(add(1,2)) + + println(sum(3,4)) + + // 调用无参方法可以不加括号 + printHello + } + + def add(x:Int,y:Int):Int={ + // 函数最后一行为返回值 + x+y + } + + /** + * 函数体只有一行可以省略括号,返回值scala会自动进行类型推断 + * @param x + * @param y + * @return + */ + def sum(x:Int,y:Int)= x + y + + def printHello()= println("Hello world!") + +} diff --git a/src/main/scala/top/fjy8018/scala/HelloWorld.scala b/src/main/scala/top/fjy8018/scala/HelloWorld.scala new file mode 100644 index 0000000..a7b121c --- /dev/null +++ b/src/main/scala/top/fjy8018/scala/HelloWorld.scala @@ -0,0 +1,7 @@ +package top.fjy8018.scala + +object HelloWorld { + def main(args: Array[String]): Unit = { + println("Hello world") + } +}