-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFactServer.java
More file actions
30 lines (27 loc) · 821 Bytes
/
FactServer.java
File metadata and controls
30 lines (27 loc) · 821 Bytes
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
import java.net.Socket;
import java.net.ServerSocket;
import java.io.*;
public class FactServer{
public static void main(String []a){
try{
System.out.println("Waiting for client....");
ServerSocket ss=new ServerSocket(12345);
Socket soc=ss.accept();
System.out.println("Connection Establish");
// data from client
BufferedReader in =new BufferedReader(new InputStreamReader(soc.getInputStream()));
int num=Integer.parseInt(in.readLine());
PrintWriter out = new PrintWriter(soc.getOutputStream(),true);
out.println(" "+num+" is "+calculateFact(num) );
}catch(Exception e){
e.printStackTrace();
}
}
static int calculateFact(int number){
int fact=1;
for(int i=1;i<=number;i++){
fact*=i;
}
return fact;
}
}