编写一个应用程序,定义2个整型变量n1,n2并赋给任意值。计算输出n1>n2,n1<n2,n1-n2>=0,n1%n2==0的值。
2个回答
展开全部
import java.lang.System;
import java.util.Random;
/**
* 枚举用法详解
*
* @author Lingo
* @version 1.0
*
*/
public class Test{
public static void main(String[] args)
{
//随机获得n1,n2的值,范围在0~100之间
Random n = new Random();
int n1 = n.nextInt(100);
int n2 = n.nextInt(100);
System.out.println("n1 = " + n1 + ", n2 = " + n2);
//打印n1 > n2(其它几个如下打印即可)0的值。Boolean类型的值:
//System.out.println(需要打印的判断语句);
System.out.println(n1 > n2);
if (n1 > n2)
System.out.println("n1>n2");
else if (n1 < n2)
System.out.println("n1<n2");
else
System.out.println("n1=n2");
if (n1 - n2 >= 0)
System.out.println("n1-n2>=0");
else
System.out.println("n1-n2<0");
if (n1 % n2 == 0)
System.out.println("n1%n2=0");
else
System.out.println("n1%n2=" + (n1 % n2));
}
}
结果:
n1 = 53, n2 = 72
false
n1<n2
n1-n2<0
n1%n2=53
展开全部
public class Number {
private Integer n1;
private Integer n2;
/** 构造方法 */
public Number(Integer n1, Integer n2) {
super();
this.n1 = n1;
this.n2 = n2;
}
/** 加 */
public Integer addition() {
System.out.println(this.n1 + this.n2);
return this.n1 + this.n2;
}
/** 减 */
public Integer subtration() {
System.out.println(this.n1 - this.n2);
return this.n1 - this.n2;
}
/** 乘 */
public Integer multiplication() {
System.out.println(this.n1 * this.n2);
return this.n1 * this.n2;
}
/** 除 */
public Integer division() {
System.out.println(this.n1 / this.n2);
return this.n1 / this.n2;
}
public Integer getN1() {
return n1;
}
public void setN1(Integer n1) {
this.n1 = n1;
}
public Integer getN2() {
return n2;
}
public void setN2(Integer n2) {
this.n2 = n2;
}
}
public static void main(String[] args) {
Number number = new Number(1, 2);
number.addition();
number.subtration();
number.multiplication();
number.division();
}
private Integer n1;
private Integer n2;
/** 构造方法 */
public Number(Integer n1, Integer n2) {
super();
this.n1 = n1;
this.n2 = n2;
}
/** 加 */
public Integer addition() {
System.out.println(this.n1 + this.n2);
return this.n1 + this.n2;
}
/** 减 */
public Integer subtration() {
System.out.println(this.n1 - this.n2);
return this.n1 - this.n2;
}
/** 乘 */
public Integer multiplication() {
System.out.println(this.n1 * this.n2);
return this.n1 * this.n2;
}
/** 除 */
public Integer division() {
System.out.println(this.n1 / this.n2);
return this.n1 / this.n2;
}
public Integer getN1() {
return n1;
}
public void setN1(Integer n1) {
this.n1 = n1;
}
public Integer getN2() {
return n2;
}
public void setN2(Integer n2) {
this.n2 = n2;
}
}
public static void main(String[] args) {
Number number = new Number(1, 2);
number.addition();
number.subtration();
number.multiplication();
number.division();
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询