public class Complex extends Object
{ private int a;
private int b;
public Complex()
{ setComplex(0,0);
}
public void setComplex(int A,int B)
{ a=A;
b=B;
}
public int toAdd()
{ return a+b;
}
public int getA()
{
return a;
}
public int getB()
{
return b;
}}
//ComplexText.java
import javax.swing.JOptionPane;
public class ComplexText
{ public static void main(String args[])
{ Complex a=new Complex();
String output;
a.setComplex(12,23);
output="\n这两个数是: "+a.getA()+a.getB()+"\n他们的和是: "+a.toAdd();
JOptionPane.showMessageDialog(null,output,"result",JOptionPane.INFORMATION_MESSAGE);
System.exit(0);
}
}
{ private int a;
private int b;
public Complex()
{ setComplex(0,0);
}
public void setComplex(int A,int B)
{ a=A;
b=B;
}
public int toAdd()
{ return a+b;
}
public int getA()
{
return a;
}
public int getB()
{
return b;
}}
//ComplexText.java
import javax.swing.JOptionPane;
public class ComplexText
{ public static void main(String args[])
{ Complex a=new Complex();
String output;
a.setComplex(12,23);
output="\n这两个数是: "+a.getA()+a.getB()+"\n他们的和是: "+a.toAdd();
JOptionPane.showMessageDialog(null,output,"result",JOptionPane.INFORMATION_MESSAGE);
System.exit(0);
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货