如何使用compareto按字典顺序打印3个数字和字母中最大的一个

cclgggtu  于 2021-06-29  发布在  Java
关注(0)|答案(0)|浏览(273)

我需要找到最大的3个数字和字母的字典使用compareto和我已经写了方法,并有驱动程序,但我不太确定如何调用该方法,或如果我有正确的方法写下任何想法?

public class Obj{
public static  Comparable  biggest (Integer word1, Integer word2, Integer
 word3) {
      Integer  big = word1.compareTo(word2);
        big = big.compareTo(word3);
        if(big<0){
            return word1;

        }else if(big>0){
                return word3;
            }
                else{
            return word2;
        }
        }

}

import java.util.Scanner;
class Main {
  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
        Integer numcompare;
        int lettercomp2;
        int lettercomp;
        System.out.println("Choose 3 numbers");
        Integer num1;
        num1 = scan.nextInt();
        Integer num2;
        num2 = scan.nextInt();
        Integer num3;
        num3 = scan.nextInt();

        numcompare = num1.compareTo(num2);
        numcompare = numcompare.compareTo(num3);
        System.out.println(numcompare);

            System.out.println("Choose 3 letters");
            String letter1;
            letter1 = scan.nextLine();
            String letter2;
            letter2 = scan.nextLine();
            String letter3;
            letter3 = scan.nextLine();

              lettercomp = letter1.compareTo(letter2);

            System.out.println(lettercomp);
        }

}

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题