Commits

Zemian Deng committed b12ba4a

Added kotlin-demo.

  • Participants
  • Parent commits df6e83e

Comments (0)

Files changed (3)

File kotlin-demo/pom.xml

+<project>
+	<modelVersion>4.0.0</modelVersion>
+	<groupId>deng</groupId>
+	<artifactId>kotlin-demo</artifactId>
+	<version>1.0.0-SNAPSHOT</version>
+	<properties>
+		<kotlin.version>0.4.68</kotlin.version>
+	</properties>
+
+	<build>
+		<sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory> 
+		<testSourceDirectory>${project.basedir}/src/test/kotlin</testSourceDirectory>
+		<plugins>
+
+			<plugin> 
+				<artifactId>kotlin-maven-plugin</artifactId> 
+				<groupId>org.jetbrains.kotlin</groupId> 
+				<version>${kotlin.version}</version> 
+
+				<executions> 
+					<execution> 
+						<id>compile</id> 
+						<phase>compile</phase> 
+						<goals> <goal>compile</goal> </goals> 
+					</execution> 
+
+					<execution> 
+						<id>test-compile</id> 
+						<phase>test-compile</phase> 
+						<goals> <goal>test-compile</goal> </goals> 
+					</execution> 
+				</executions> 
+			</plugin>
+		</plugins>
+
+	</build>
+
+	<dependencies> 
+		<dependency> 
+			<groupId>org.jetbrains.kotlin</groupId> 
+			<artifactId>kotlin-stdlib</artifactId> 
+			<version>${kotlin.version}</version> 
+		</dependency> 
+	</dependencies>
+
+	<repositories>
+		<repository>
+			<id>jetbrains-all</id>
+			<url>http://repository.jetbrains.com/all</url>
+		</repository>
+	</repositories>
+
+	<pluginRepositories>
+		<pluginRepository>
+			<id>jetbrains-all</id>
+			<url>http://repository.jetbrains.com/all</url>
+		</pluginRepository>
+	</pluginRepositories>
+</project>

File kotlin-demo/src/main/kotlin/Hello.kt

+package deng
+
+fun main(args : Array<String>) {
+	println("Hello")
+
+	val max : Int = if (args.size >= 1) args[0].toInt() else 10
+	for (i in (0..max))
+		println(fact2(i))
+}
+
+fun fact(n : Int) : Int {
+	if (n <= 1) return 1
+	else return n * fact(n -1)
+}
+
+fun fact2(n : Int) : Int {
+	when (n) {
+		0, 1 -> return 1
+		else -> return n * fact2(n - 1)
+	}
+}

File kotlin-demo/src/main/kotlin/Hello2.kt

+package deng2
+
+fun main(args : Array<String>) {
+	println("Hello2")
+}