OUTPUT :-
PROGRAM :-
import java.util.Scanner;
public class Echo {
public static void main(String[] args) {
String inData;
Scanner scan = new Scanner(System.in);
System.out.println("Enter the data:");
inData = scan.nextLine();
System.out.println("You entered: " + inData);
}
}
RESULT :-
Thus the Program has been successfully done and the Output is verified.
OUTPUT :-
PROGRAM :-
SERVER SIDE :-
import java.net.*;
import java.io.*;
public class Server {
public static void main(String[] args) {
try {
ServerSocket ss = new ServerSocket(1999);
Socket s = ss.accept( );
DataInputStream dis = new DataInputStream(s.getInputStream());
System.out.println(dis.readUTF());
} catch (IOException ie) {
ie.printStackTrace();
}
}
}
CLIENT SIDE:-
import java.net.*;
import java.io.*;
public class Client {
public static void main(String[] args) {
try {
Socket s = new Socket("172.20.105.69", 1999);
DataOutputStream dos = new DataOutputStream(s.getOutputStream());
dos.writeUTF("Hello");
dos.close(); // Close the DataOutputStream
s.close(); // Close the Socket
} catch (IOException e) {
e.printStackTrace();
}
}
}
RESULT :-
Thus the Program has been successfully done and the Output is verified.
OUTPUT :-
PROGRAM :-
import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
public class Ping {
public static void sendPingRequest(String ipAddress) throws
UnknownHostException, IOException {
InetAddress geek = InetAddress.getByName(ipAddress);
System.out.println("Sending Ping Request to " + ipAddress);
if (geek.isReachable(5000)) {
System.out.println("Host is reachable");
} else {
System.out.println("Sorry! We can't reach to this host");
}
}
public static void main(String[] args) throws
UnknownHostException, IOException {
String ipAddress = "172.20.105.46";
sendPingRequest(ipAddress);
}
}
RESULT :-
Thus the Program has been successfully done and the Output is verified.
OUTPUT :-
PROGRAM :-
SERVER SIDE :-
import java.io.*;
import java.net.*;
public class ServerRCE {
public static void main(String args[]) throws IOException {
try {
String str;
ServerSocket server = new ServerSocket(6555);
Socket s = server.accept();
BufferedReader br = new BufferedReader(new
InputStreamReader(s.getInputStream()));
str = br.readLine();
Runtime r = Runtime.getRuntime();
Process p = r.exec(str);
} catch (IOException e) {
System.out.println("Error");
}
}
}
CLIENT SIDE :-
import java.io.*;
import java.net.*;
public class ClientRCE {
public static void main(String args[]) throws IOException {
try {
String str;
Socket client = new Socket("localhost", 6555);
PrintStream ps = new PrintStream(client.getOutputStream());
BufferedReader br = new BufferedReader (new
InputStreamReader(System.in));
System.out.println("Enter The Command: ");
str = br.readLine();
ps.println(str);
ps.close();
br.close();
client.close();
} catch (IOException e) {
System.out.println("Error");}
}
}
RESULT :-
Thus the Program has been successfully done and the Output is verified.
OUTPUT :-
PROGRAM :-
import java.util.Scanner;
public class CRC {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n, m, i, j, k;
System.out.print("ENTER NUMBER OF DATA BITS:\n");
n = sc.nextInt();
System.out.print("ENTER NUMBER OF GENERATOR BITS:\n");
m = sc.nextInt();
int[] d = new int[n + m];
int[] g = new int[m];
System.out.print("ENTER DATA BITS:\n");
for (i = 0; i < n; i++)
d[i] = sc.nextInt();
System.out.print("ENTER GENERATOR BITS:\n");
for (i = 0; i < m; i++)
g[i] = sc.nextInt();
for (i = 0; i < m - 1; i++)
d[n + i] = 0;
int[] r = new int[m + n];
for (i = 0; i < m; i++)
r[i] = d[i];
int[] z = new int[m];
for (i = 0; i < m; i++)
z[i] = 0;
System.out.print("\nTHE CODE BITS ADDED ARE:\n");
for (i = n; i < n + m - 1; i++) {
k = 0;
int msb = r[i];
for (j = 1; j < m + i; j++) {
if (msb == 0)
r[i] = xor(r[j], z[k]);
else
r[i] = xor(r[j], g[k]);
k++;
}
d[i] = r[i];
System.out.print(d[i]);
}
System.out.println("\nTHE CODE DATA IS:");
for (i = 0; i < n + m - 1; i++) {
System.out.print(d[i]);
}
}
public static int xor(int x, int y) {
if (x == y)
return 0;
else
return 1;
}
}
RESULT :-
Thus the Program has been successfully done and the Output is verified.
OUTPUT :-
PROGRAM :-
public class SlidingWindow {
static int maxSum(int[] arr, int k) {
int n = arr.length;
if (n < k) {
System.out.println("Invalid");
return -1;
}
int windowSum = 0;
for (int i = 0; i < k; i++) {
windowSum += arr[i];
}
int maxSum = windowSum;
for (int i = k; i < n; i++) {
windowSum += (arr[i] - arr[i - k]);
maxSum = Math.max(windowSum, maxSum);
}
return maxSum;
}
public static void main(String[] args) {
int k = 3;
int[] arr = {16, 12, 9, 1, 5, 8};
System.out.println(maxSum(arr, k));
}
}
RESULT :-
Thus the Program has been successfully done and the Output is verified.
OUTPUT :-
PROGRAM :-
import java.util.Scanner;
public class TalkCommand {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Welcome to Talk Command!");
System.out.println("Type 'exit' to quit.");
while (true) {
System.out.print("You: ");
String input = scanner.nextLine();
if (input.equalsIgnoreCase("exit")) {
System.out.println("Exiting Talk Command. Goodbye!");
break;
}
System.out.println("Talk Command: Hello, you said: " + input);
}
scanner.close();
}
}
RESULT :-
Thus the Program has been successfully done and the Output is verified.
OUTPUT :-
PROGRAM :-
CLIENT SIDE :-
import java.net.*;
import java.io.*;
public class Client1 {
public static void main (String []args) {
try {
Socket s = new Socket("localhost", 1999);
DataOutputStream dos = new DataOutputStream(s.getOutputStream());
DataInputStream dis = new DataInputStream(s.getInputStream());
(System.in));
BufferedReader br = new BufferedReader(new InputStreamReader
while(!br.readLine().equals("quit")) {
dos.writeUTF(br.readLine());
System.out.println("He says: " + dis.readUTF());
dos.flush();
}
s.close();
} catch (IOException ie) {
ie.printStackTrace();
}
}
}
SERVER SIDE :-
import java.net.*;
import java.io.*;
public class Server1 {
public static void main (String []args) {
try {
ServerSocket ss = new ServerSocket (1999);
Sockets ss.accept();
DataOutputStream dos = new DataOutputStream(s.getOutputStream());
DataInputStream dis = new DataInputStream(s.getInputStream());
(System.in));
BufferedReader br = new BufferedReader(new InputStreamReader
while(!br.readLine().equals("quit")) {
System.out.println("She says: " + dis.readUTF());
dos.writeUTF(br.readLine());
}
ss.close();
} catch (Exception ie) {
ie.printStackTrace();
}}
}
RESULT :-
Thus the Program has been successfully done and the Output is verified.