that's it for today
This commit is contained in:
14
Semester 2/RecursionDemo/pom.xml
Normal file
14
Semester 2/RecursionDemo/pom.xml
Normal file
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>edu.slcc.asdv.caleb</groupId>
|
||||
<artifactId>RecursionDemo</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.source>20</maven.compiler.source>
|
||||
<maven.compiler.target>20</maven.compiler.target>
|
||||
<exec.mainClass>edu.slcc.asdv.caleb.recursiondemo.RecursionDemo</exec.mainClass>
|
||||
</properties>
|
||||
</project>
|
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
*/
|
||||
package edu.slcc.asdv.caleb.recursiondemo;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
public class RecursionDemo {
|
||||
|
||||
static void printNTimes(int nTimes, String message)
|
||||
{
|
||||
for (int i = 0; i < nTimes; ++i) {
|
||||
System.out.println(message);
|
||||
}
|
||||
}
|
||||
|
||||
static void printNTimesRecursion(int nTimes, String message)
|
||||
{
|
||||
if (nTimes == 0) {
|
||||
return;
|
||||
}
|
||||
System.out.println(message);
|
||||
printNTimesRecursion(--nTimes, message);
|
||||
}
|
||||
|
||||
public static long factorial(int n)
|
||||
{
|
||||
long fact;
|
||||
if (n == 1)
|
||||
return 1;
|
||||
fact = n * factorial(n - 1);
|
||||
return fact;
|
||||
}
|
||||
|
||||
public static void main(String[] args)
|
||||
{
|
||||
System.out.println(factorial(20));
|
||||
printNTimesRecursion(1, "Hello Recursion");
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user