package com.test.Test08; public class Test01 { public static void main(String[] args) { /*//int类型比较大小 int a = 10; int b = 20; System.out.println(a-b); //=0 >0 <0 //res:-10*/ //String类型比较大小 /*String a = "A"; String b = "B"; System.out.println(a.compareTo(b));//-1*/ //double比较大小 double a = 9.6; double b = 9.3; //System.out.println(a-b); //System.out.println((int)a-b); //Double底层类里面也有compareTo这个函数 System.out.println(((Double) a).compareTo((Double) b)); //1 } }
int类型,String类型,double类型比较大小
![](https://img-home.csdnimg.cn/images/20240711042549.png)