Question:
Write a Java program that implements a simple Client/Server application.?
Renu
2012-10-31 06:42:23 UTC
The client sends data to a server(remote machine). The server receives the data, uses it to produce a result, and then sends the result back to the client. The client displays the result on the screen. Implement the above scenario for Swapping two numbers.
Three answers:
Prashant
2012-10-31 14:28:04 UTC
Client-Server Java program

http://electrofriends.com/source-codes/software-programs/java/advanced-programs/java-program-that-finds-the-area-of-a-circle-using-client-server-network/



Swapping of two numbers



static void swap(int i,int j){

int temp=i;

i=j;

j=temp;

System.out.println("After swapping i = " + i + " j = " + j);

}

public static void main(String[] args){

int i=1;

int j=2;

System.out.prinln("Before swapping i="+i+" j="+j);

swap(i,j);

}
?
2012-10-31 22:37:25 UTC
Hi,



import java.io.*;

import java.net.*;

class Client

{

public static void main(String ar[])throws Exception

{

Socket s=new Socket(InetAddress.getLocalHost(),10000);

System.out.println("enter the radius of the circle ");

DataInputStream dis=new DataInputStream(System.in);

int n=Integer.parseInt(dis.readLine());

PrintStream ps=new PrintStream(s.getOutputStream());

ps.println(n);

DataInputStream dis1=new DataInputStream(s.getInputStream());

System.out.println("area of the circle from server:"+dis1.readLine());

}

}

import java.io.*;

import java.net.*;

class Server

{

public static void main(String ar[])throws Exception

{

ServerSocket ss=new ServerSocket(10000);

Socket s=ss.accept();

DataInputStream dis=new DataInputStream(s.getInputStream());

int n=Integer.parseInt(dis.readLine());

PrintStream ps=new PrintStream(s.getOutputStream());

ps.println(3.14*n*n);

}

}
2016-02-21 05:24:58 UTC
dude try to use arraysto store each input and print each value of array without using prinln , e.g using system.out.print(array[1]+" "+array[2]+" " + ...araay[5])"


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...