-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathserver.java
More file actions
47 lines (36 loc) · 1.14 KB
/
server.java
File metadata and controls
47 lines (36 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import java.io.IOException;
import java.io.PrintStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Scanner;
class Combination{
private int factorial(int n) {
int temp = n, prod = 1;
while (temp != 1) {
prod *= temp;
temp--;
}
return prod;
}
public float combinationCalc(int n, int r){
return (float)factorial(n)/(factorial(n-r) * factorial(r));
}
}
public class server {
public static void main(String[] args) throws IOException {
int number1, number2;
float result;
// Server Socket
ServerSocket ss = new ServerSocket(8000);
Socket so = ss.accept();
System.out.println("Server is Ready!");
Scanner sc = new Scanner(so.getInputStream());
number1 = sc.nextInt(); // Stream input from client
number2 = sc.nextInt();
Combination cb = new Combination();
result = cb.combinationCalc(number1, number2); // manipulation to result
//output to stream
PrintStream p = new PrintStream(so.getOutputStream());
p.println(result);
}
}