作业不会啊~~~麻烦各位哥哥姐姐帮忙!JAVA编程题,

来源:百度知道 编辑:UC知道 时间:2024/05/10 13:19:25
1:定义一个类,类中有两个整型变量x和y,并定义构造函数初始化这两个变量。类中还定义以下方法:求两个数的和(x+y)并返回结果,求两个数的差(x-y)并返回结果,求两个数的的乘积(x*y)并返回结果,求两个数的商(x/y)并返回结果,求两个睡的余(x%y)并返回结果,求两个数的最大值并返回结果,求两个数的最小值并返回结果。
编写应用程序,测试上面定义的类,使用类中定义的各个方法并将其结果输出。
public class Class1 {
public static void main(String[] args) {
//定义几个数
int x = 37,y = 42,maxValue,minValue;
System.out.println("变量数值...");
System.out.println(" x = " + x);
System.out.println(" y = " + y);
//加
System.out.println("加...");
System.out.println(" x + y = " + (x + y));
//减
System.out.println("减...");
System.out.println(" x - y = " + (x - y));
//乘
System.out.println("乘...");
System.out.println(" x * y = " + (x * y));
//除
System.out.println("除...");
System.out.println(" x / y = " + (x / y));
//从除法中求得余数
System.ou

public class IntegerTest
{
int x;
int y;

public IntegerTest(int x,int y)
{
this.x=x;
this.y=y;
}

public int sum()
{
return this.x+this.y;
}

public int minus()
{
return this.x-this.y;
}

public int multiply()
{
return this.x*this.y;
}

public int chu()
{
return this.x/this.y;
}

public int mod()
{
return this.x%this.y;
}

public int max()
{
if(this.x>=this.y)
{
return this.x;
}
return this.y;
}

public int min()
{
if(this.x<=this.y)
{
return this.x;
}
return this.y;
}

public static void main(String args[])
{
IntegerTest i=new IntegerTest(2,3);
System.out.println("x+y="+i.sum()+"\nx-y="+i.minus()+"