class Complex{
private int realPart;
private int imaginPart;
Complex(){
thisrealPart = 0;
thisimaginPart = 0;
}
Complex(int realPart, int imaginPart){
thisrealPart = realPart;
thisimaginPart = imaginPart;
}
public void setRealPart(int realPart){
thisrealPart = realPart;
}
public void setImaginPart(int imaginPart){
thisimaginPart = imaginPart;
}
public int getRealPart(){
return thisrealPart;
}
public int getImaginPart(){
return thisimaginPart;
}
Complex complexAdd(Complex a){
int realPart = thisrealPart + agetRealPart();
int imaginPart = thisimaginPart + agetImaginPart();
return new Complex(realPart, imaginPart);
}
public String toString(){
if(thisimaginPart == 0) return "" + thisrealPart;
else if(thisimaginPart > 0) return "" + thisrealPart + "+" + thisimaginPart + "i";
else return "" + thisrealPart + thisimaginPart + "i";
}
}
public class TestComplex{
public static void main(String[] args){
Complex a = new Complex(1,2);
Complex b = new Complex(3,4);
Complex sum = acomplexAdd(b);
Systemoutprintln("(" + a + ")" + "+" + "(" + b + ")" + "=" + "(" + sum + ")");
asetRealPart(2);
asetImaginPart(3);
bsetRealPart(bgetRealPart() 2);
bsetImaginPart(bgetImaginPart() 2);
sum = acomplexAdd(b);
Systemoutprintln("(" + a + ")" + "+" + "(" + b + ")" + "=" + "(" + sum + ")");
}
}
int a=2;
int b=1;
double result=0;
for(int i=1;i<=20;i++) {
result+=a/b;
a+=b;
b=a;
}
Systemoutprintln(result);
javanet
类:DatagramPacket
DatagramSocket
或者:ServerSocket
Socket
这些类都有一个返回端口的方法,ServerSocket是getLocalPort() ,其他三个是getPort()。如果返回的端口是80,那么就禁止接收或者发送数据,并给与适当的提示信息。
以上就是关于JAVA程序设计 急要 谢谢~~~全部的内容,包括:JAVA程序设计 急要 谢谢~~~、有大佬会java编程题吗求思路和代码,谢谢!、java编程:用java做一个简单的防火墙思路:等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)