Server_PTB2_TCP
import java.io.*;
import java.net.*;
import java.util.*;
class PTB2_TCP_Server
{
public static void main(String arg[])throws Exception
{
ServerSocket sksv=new ServerSocket(6789);
while(true)
{
Socket socketconnect=sksv.accept();
DataInputStream hieu=new DataInputStream(socketconnect.getInputStream());
Double a=hieu.readDouble();
System.out.print("a: "+a);
Double b=hieu.readDouble();
System.out.print("b: "+b);
Double c=hieu.readDouble();
System.out.print("c: "+c);
String ketqua=ptb2(a,b,c);
DataOutputStream gui=new DataOutputStream(socketconnect.getOutputStream());
gui.writeUTF(ketqua);
System.out.print("Da gui ket qua "+ketqua);
}
}
public static String ptb2(double a,double b,double c)
{
double delta=b*b-4*a*c;
if(delta<0)
return "ptvn";
else
if(delta==0)
{
double x=(double)-b/(2*a);
return "pt co 2 nghiem x1=x2="+x;
}
else
{
double x1=(-b-Math.sqrt(delta))/(2*a);
double x2=(-b+Math.sqrt(delta))/(2*a);
return "pt co 2 nghiem pb x1="+x1+";x2="+x2;
}
}
}
Bạn đang đọc truyện trên: AzTruyen.Top