首页 > 试题广场 >

判断两个数的大小关系

[编程题]判断两个数的大小关系
  • 热度指数:153387 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 256M,其他语言512M
  • 算法知识视频讲解
KiKi想知道从键盘输入的两个数的大小关系,请编程实现。

输入描述:
题目有多组输入数据,每一行输入两个整数(范围-231~231-1),用空格分隔。


输出描述:
针对每行输入,输出两个整数及其大小关系,数字和关系运算符之间没有空格,详见输入输出样例。
示例1

输入

1 1

输出

1=1
示例2

输入

1 0

输出

1>0
示例3

输入

0 1

输出

0<1
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;

/**
 * @Title: 判断两个数的大小关系
 * @Remark: KiKi想知道从键盘输入的两个数的大小关系,请编程实现。
 *          输入描述:
 *              题目有多组输入数据,每一行输入两个整数(范围-231~231-1),用空格分隔。
 *          输出描述:
 *              针对每行输入,输出两个整数及其大小关系,数字和关系运算符之间没有空格,详见输入输出样例。
 *
 * @Author: ijunfu
 * @Version: 1.0.0
 * @Date: 2022-03-19
 */
public class Main {

    public static void main(String[] args) {

        Scanner in = new Scanner(System.in);

        while(in.hasNextLine()) {
            List<Integer> list = Arrays.stream(in.nextLine().split(" ")).map(x -> Integer.valueOf(x)).collect(Collectors.toList());
            int num1 = list.get(0);
            int num2 = list.get(1);

            if(num1 == num2) {
                System.out.printf("%d=%d\n", num1, num2);
            } else if(num1 < num2) {
                System.out.printf("%d<%d\n", num1, num2);
            } else {
                System.out.printf("%d>%d\n", num1, num2);
            }
           
        }

    }

}

发表于 2022-03-19 12:29:19 回复(0)
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int a;
        int b;
        char ch;
        while (in.hasNextInt()) {
            a = in.nextInt();
            b = in.nextInt();
            if (a > b) {
                ch = '>';
            } else if (a < b) {
                ch = '<';
            } else {
                ch = '=';
            }
            System.out.printf("%d%c%d\n",a,ch,b);
        }
    }
}

发表于 2021-10-20 16:46:40 回复(0)
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            Integer i = sc.nextInt();
            Integer j = sc.nextInt();
            System.out.println(i+Main.MaxNumber(i, j)+j);
        }
    }
    public static String MaxNumber(Integer i,Integer j){
        if(i-j>0){
            return ">";
        }
        else  if(i-j<0){
            return "<";
        }
        else return "=";
    }
}

发表于 2021-08-15 20:38:05 回复(0)
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while(sc.hasNextInt()){
            int a = sc.nextInt();
            int b = sc.nextInt();
            if(a>b)
                System.out.println(a+">"+b);
            else if(a<b)
                System.out.println(a+"<"+b);
            else
                System.out.println(a+"="+b);
        }
    }
}
发表于 2021-07-22 09:25:35 回复(0)
这个简单
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner input=new Scanner(System.in);
        while(input.hasNext()){
            int a=input.nextInt();
            int b=input.nextInt();
            if(a==b) System.out.println(a+"="+b);
            else System.out.println(a>b?a+">"+b:a+"<"+b);
        }
    }
}
	

发表于 2020-10-29 20:42:29 回复(0)
import java.util.*;
public class Main
{
    public static void main(String [] args)
    {
        Scanner sc=new Scanner(System.in);
        while(sc.hasNextInt())
        {
            int a=sc.nextInt();
            int b=sc.nextInt();
            if(a>b)
            {
                System.out.println(a+">"+b);
            }
            else if(a<b)
            {
                System.out.println(a+"<"+b);
            }
            else
            {
                System.out.println(a+"="+b);
            }
        }
    }
}
发表于 2020-03-26 08:43:24 回复(0)