anotherCha
This commit is contained in:
parent
f384067ac0
commit
a66ffc8910
BIN
Application.class
Normal file
BIN
Application.class
Normal file
Binary file not shown.
33
Application.java
Normal file
33
Application.java
Normal file
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
BIN
FibonacciSEQUENSE.class
Normal file
BIN
FibonacciSEQUENSE.class
Normal file
Binary file not shown.
35
FibonacciSEQUENSE.java
Normal file
35
FibonacciSEQUENSE.java
Normal file
@ -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;
|
||||
}
|
||||
}
|
||||
BIN
Grains.class
Normal file
BIN
Grains.class
Normal file
Binary file not shown.
22
Grains.java
Normal file
22
Grains.java
Normal file
@ -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;
|
||||
}
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
BIN
target/classes/PrepSession/Alonea.class
Normal file
BIN
target/classes/PrepSession/Alonea.class
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user