-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFactServer.java
More file actions
26 lines (26 loc) · 769 Bytes
/
FactServer.java
File metadata and controls
26 lines (26 loc) · 769 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
import java.io.*;
import java.net.*;
class FactServer
{
public static void main(String[] args) throws Exception
{
ServerSocket ss=new ServerSocket(9999);
Socket s=ss.accept();
BufferedReader sbr=new BufferedReader(new InputStreamReader(s.getInputStream()));
String str=sbr.readLine();
System.out.println("Number received:" + str);
int num=Integer.parseInt(str);
int fact= factorial(num);
PrintStream str2=new PrintStream(s.getOutputStream());
str2.println(String.valueOf(fact));
s.close();
ss.close();
}
public static int factorial(int n)
{
if(n==1)
return 1;
else
return n*factorial(n-1);
}
}