package com;
import java.util.Scanner;
public class Demo {
public static void main(String[] argss) {
Scanner sc = new Scanner (System.in);
System.out.println("请输入第一个数");
int nextInt = sc.nextInt();
System.out.println("请输入第二个数");
int nextInt2 = sc.nextInt();
if(nextInt < nextInt2){
int n = nextInt2 - nextInt;
System.out.println("第二个数比第一个数大:"+n);
}else if(nextInt > nextInt2){
int d = nextInt - nextInt2;
System.out.println("第二个数比第一个数小:"+d);
}else {
System.out.println("这两个数相等");
}
}
}
没用使用复杂逻辑判断,只用了简单的if else 希望能满足需求
import java.util.Scanner;
public class demo
{
public static void main(String[] args)
{
int a,b;
System.out.println("请输入第一个整数:");
Scanner sc = new Scanner(System.in);
a=sc.nextInt();
System.out.println("请输入第二个整数:");
b=sc.nextInt();
if (a>b)
{
System.out.println("两个数比较相差:"+(a-b));
}
else if (a==b)
{
System.out.println("两个整数相等");
}
else {
System.out.println("两个数比较相差:"+(b-a));
}
}
}