diff --git a/Application.class b/Application.class new file mode 100644 index 0000000..a644ea1 Binary files /dev/null and b/Application.class differ diff --git a/Application.java b/Application.java new file mode 100644 index 0000000..3fb9971 --- /dev/null +++ b/Application.java @@ -0,0 +1,33 @@ +import java.io.OutputStream; +import java.net.InetSocketAddress; +import com.sun.net.httpserver.HttpServer; + +public class Application { + public static void main(String[] args) throws Exception { + int serverPort = 8084; + + // Create an HTTP server and bind it to the specified port + HttpServer server = HttpServer.create(new InetSocketAddress(serverPort), 0); + + // Create a context for the "/api/hello" endpoint + server.createContext("/api/hello", (exchange -> { + String respText = "Hello world"; // The response text + + // Send the response headers (HTTP 200 OK, content length of the response) + exchange.sendResponseHeaders(200, respText.getBytes().length); + + // Get the response body output stream and write the response to it + OutputStream outputStream = exchange.getResponseBody(); + outputStream.write(respText.getBytes()); + outputStream.flush(); + + // Close the exchange to finish the request + exchange.close(); + })); + + server.setExecutor(null); // Use default executor + server.start(); // Start the server + System.out.println("Server started on port " + serverPort); + } +} + diff --git a/FibonacciSEQUENSE.class b/FibonacciSEQUENSE.class new file mode 100644 index 0000000..546373e Binary files /dev/null and b/FibonacciSEQUENSE.class differ diff --git a/FibonacciSEQUENSE.java b/FibonacciSEQUENSE.java new file mode 100644 index 0000000..643c27d --- /dev/null +++ b/FibonacciSEQUENSE.java @@ -0,0 +1,35 @@ +import java.util.Scanner; + +/** + * FibonacciSEQUENSE + */ +public class FibonacciSEQUENSE { + + public static long[] fibCache; + + public static void main(String[] args) { + // 1 1 2 3 5 8 13 + Scanner sc = new Scanner(System.in); + + System.out.println("Please enter a number to get the corresponding Fibonacci Number: "); + int x = sc.nextInt(); + fibCache = new long[1 + x]; + + for (int i = 0; i < x; i++) { + System.out.println(fibSequence(i)); + } + sc.close(); + } + + public static long fibSequence(int n) { + if (n <= 1) { + return n; + } + if (fibCache[n] != 0) { + return fibCache[n]; + } + long fibNum = (fibSequence(n - 1) + fibSequence(n - 2)); + fibCache[n] = fibNum; + return fibNum; + } +} diff --git a/Grains.class b/Grains.class new file mode 100644 index 0000000..fa5af68 Binary files /dev/null and b/Grains.class differ diff --git a/Grains.java b/Grains.java new file mode 100644 index 0000000..47ff437 --- /dev/null +++ b/Grains.java @@ -0,0 +1,22 @@ +/** + * Grains + */ +public class Grains { + + public static void main(String[] args) { + + System.out.println(grainsCount()); + } + + public static double grainsCount() { + // Calculate the number of grains of wheat on a chessboard given that the number + // on each square doubles. + double gCount = 0; + double grainOnCurrentSQ = 1; + for (int i = 1; i <= 64; i++) { + gCount += grainOnCurrentSQ; + grainOnCurrentSQ *= 2; + } + return gCount; + } +} diff --git a/target/classes/Alone.class b/target/classes/Alone.class index e09556c..5d5db3a 100644 Binary files a/target/classes/Alone.class and b/target/classes/Alone.class differ diff --git a/target/classes/Alonea.class b/target/classes/Alonea.class deleted file mode 100644 index 0feda4e..0000000 Binary files a/target/classes/Alonea.class and /dev/null differ diff --git a/target/classes/PrepSession/Alonea.class b/target/classes/PrepSession/Alonea.class new file mode 100644 index 0000000..de1e00b Binary files /dev/null and b/target/classes/PrepSession/Alonea.class differ