Recursion hell
This commit is contained in:
parent
40238e93f4
commit
b6fea4bfef
5
.gitignore
vendored
5
.gitignore
vendored
@ -123,11 +123,8 @@
|
|||||||
/Semester 2/Assignments/JavaFX_CalebFontenot/target/
|
/Semester 2/Assignments/JavaFX_CalebFontenot/target/
|
||||||
/Semester 2/Assignments/JavaFX_CalebFontenot/nbproject/private/
|
/Semester 2/Assignments/JavaFX_CalebFontenot/nbproject/private/
|
||||||
/Semester 2/Assignments/JavaFX_CalebFontenot/build/
|
/Semester 2/Assignments/JavaFX_CalebFontenot/build/
|
||||||
<<<<<<< Updated upstream
|
|
||||||
/Semester 2/Exams/ProgrammingExam2_CalebFontenot/nbproject/private/
|
/Semester 2/Exams/ProgrammingExam2_CalebFontenot/nbproject/private/
|
||||||
/Semester 2/Exams/ProgrammingExam2_CalebFontenot/build/
|
/Semester 2/Exams/ProgrammingExam2_CalebFontenot/build/
|
||||||
=======
|
|
||||||
>>>>>>> Stashed changes
|
|
||||||
/Semester 2/Assignments/bruh/nbproject/private/
|
/Semester 2/Assignments/bruh/nbproject/private/
|
||||||
/Semester 2/Exams/Exam2-Practice_CalebFontenot/target/
|
/Semester 2/Exams/Exam2-Practice_CalebFontenot/target/
|
||||||
/Semester 2/Exams/Exam2-Practice1_CalebFontenot/target/
|
/Semester 2/Exams/Exam2-Practice1_CalebFontenot/target/
|
||||||
@ -148,3 +145,5 @@
|
|||||||
/Semester 3/Assignments/MP1_FX_CalebFontenot/build/
|
/Semester 3/Assignments/MP1_FX_CalebFontenot/build/
|
||||||
/Semester 3/Assignments/MP1_FX_CalebFontenot/dist/
|
/Semester 3/Assignments/MP1_FX_CalebFontenot/dist/
|
||||||
/Semester 3/Assignments/RecursionDemo/target/
|
/Semester 3/Assignments/RecursionDemo/target/
|
||||||
|
/Semester 3/Assignments/lab5-recursion2_CalebFontenot/target/
|
||||||
|
|
||||||
|
14
Semester 3/Assignments/lab5-recursion2_CalebFontenot/pom.xml
Normal file
14
Semester 3/Assignments/lab5-recursion2_CalebFontenot/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>lab5-recursion2_CalebFontenot</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.lab5.recursion2_calebfontenot.Lab5Recursion2_CalebFontenot</exec.mainClass>
|
||||||
|
</properties>
|
||||||
|
</project>
|
Binary file not shown.
@ -0,0 +1,16 @@
|
|||||||
|
/*
|
||||||
|
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||||
|
*/
|
||||||
|
|
||||||
|
package edu.slcc.asdv.caleb.lab5.recursion2_calebfontenot;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author caleb
|
||||||
|
*/
|
||||||
|
public class Lab5Recursion2_CalebFontenot {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
System.out.println("Hello World!");
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,33 @@
|
|||||||
|
/*
|
||||||
|
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||||
|
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||||
|
*/
|
||||||
|
package edu.slcc.asdv.caleb.lab5.recursion2_calebfontenot;
|
||||||
|
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author caleb
|
||||||
|
*/
|
||||||
|
public class OccurancesOfChar {
|
||||||
|
public static void main(String[] args)
|
||||||
|
{
|
||||||
|
Scanner input = new Scanner(System.in);
|
||||||
|
System.out.print("Enter a string: ");
|
||||||
|
String s = input.nextLine();
|
||||||
|
System.out.print("Enter a character: ");
|
||||||
|
char ch =input.nextLine().charAt(0);
|
||||||
|
int times = count(s, ch);
|
||||||
|
System.out.println(ch + " appears " + times
|
||||||
|
+ (times > 1 ? " times " : " time ") + "in " + s);
|
||||||
|
}
|
||||||
|
public static int count(String str, char a) {
|
||||||
|
int result = 0;
|
||||||
|
if (str.length() > 0) {
|
||||||
|
result = count(str.substring(1), a) +
|
||||||
|
(( str.charAt(0) == a) ? 1 : 0);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,30 @@
|
|||||||
|
/*
|
||||||
|
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||||
|
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||||
|
*/
|
||||||
|
package edu.slcc.asdv.caleb.lab5.recursion2_calebfontenot;
|
||||||
|
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author caleb
|
||||||
|
*/
|
||||||
|
public class ReverseInt {
|
||||||
|
public static void main(String[] args)
|
||||||
|
{
|
||||||
|
Scanner input = new Scanner(System.in);
|
||||||
|
System.out.print("Enter an integer: ");
|
||||||
|
int i = input.nextInt();
|
||||||
|
System.out.print("The reversal of " + i + " is ");
|
||||||
|
reverseDisplay(i);
|
||||||
|
System.out.println();
|
||||||
|
}
|
||||||
|
public static void reverseDisplay(int value) {
|
||||||
|
if (value != 0) {
|
||||||
|
System.out.print(value % 10);
|
||||||
|
value = value / 10;
|
||||||
|
reverseDisplay(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,26 @@
|
|||||||
|
/*
|
||||||
|
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||||
|
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||||
|
*/
|
||||||
|
package edu.slcc.asdv.caleb.lab5.recursion2_calebfontenot;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author caleb
|
||||||
|
*/
|
||||||
|
public class SumSeries1 {
|
||||||
|
public static void main(String[] args)
|
||||||
|
{
|
||||||
|
System.out.printf("%-10s%15s\n", "1", "m(i)");
|
||||||
|
for (int i = 1; i <= 10; ++i) {
|
||||||
|
System.out.printf("%-10d%-15.6f\n",i, m(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public static double m(int i) {
|
||||||
|
if (i == 1) {
|
||||||
|
return 1;
|
||||||
|
} else {
|
||||||
|
return m(i - 1) + 1.0 / i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,26 @@
|
|||||||
|
/*
|
||||||
|
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||||
|
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||||
|
*/
|
||||||
|
package edu.slcc.asdv.caleb.lab5.recursion2_calebfontenot;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author caleb
|
||||||
|
*/
|
||||||
|
public class SumSeries2 {
|
||||||
|
public static void main(String[] args)
|
||||||
|
{
|
||||||
|
System.out.printf("%-10s%15s\n", "i", "m(i)");
|
||||||
|
for (int i = 1; i <= 10; ++i) {
|
||||||
|
System.out.printf("%-10d%-15.6f\n",i, m(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public static double m(int i) {
|
||||||
|
if (i == 1) {
|
||||||
|
return 1.0 / 3;
|
||||||
|
} else {
|
||||||
|
return m(i - 1) + (double) i / (2 * i + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user