A)
Write a Java program to accept a number through client terminal, send it to the
Server,
Server calculates its factors and sends it to the client.
Answer :
//Client
import java.io.*;
import java.net.*;
class Slip25A {
public static void main(String args[]) throws Exception {
Socket s = new Socket("localhost", 2121);
DataInputStream din = new DataInputStream(System.in);
System.out.print("Enter the number : ");
String n = din.readLine();
DataOutputStream dos = new DataOutputStream(s.getOutputStream());
dos.writeBytes(n + "\n");
System.out.println("<<<<Factors>>>>");
int arr[] = new int[15];
DataInputStream dis = new DataInputStream(s.getInputStream());
for (int i = 0; i < 15; i++) {
arr[i] = dis.readInt();
System.out.println(arr[i] + " ");
}
}
}
//Server
import java.io.*;
import java.net.*;
import java.util.Date;
class Slip25A1 {
public static void main(String args[]) throws Exception {
ServerSocket ss = new ServerSocket(2121);
Socket s = ss.accept();
DataInputStream dis = new DataInputStream(s.getInputStream());
int n = Integer.parseInt(dis.readLine());
int arr[] = new int[15];
int i, j = 0;
DataOutputStream dos = new DataOutputStream(s.getOutputStream());
for (i = 1; i <= n; i++) {
if (n % i == 0) {
arr[j] = i;
dos.writeInt(arr[j]);
j++;
} else {
arr[j] = arr[j - 1];
}
}
s.close();
}
}
B)
Write a Java Program for the following: Assume database is already created.
Answer :
Output :
No comments:
Post a Comment