当前位置:首页 » 编程语言 » javainteger比较

javainteger比较

发布时间: 2024-06-03 02:14:39

1. 用java语言程序,比较三个数的大小,输出最大的那个数

你好,帮你写了一个例子:
import java.lang.Math;
import java.util.Scanner;
public class max {
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
System.out.println("Please input 3 integers: ");
int x = Integer.parseInt(keyboard.nextLine());
int y = Integer.parseInt(keyboard.nextLine());
int z = Integer.parseInt(keyboard.nextLine());
int max = Math.max(x,y);
if(max>y){ //suppose x is max then compare x with z to find max number
max = Math.max(x,z);
}
else{ //if y is max then compare y with z to find max number
max = Math.max(y,z);
}
System.out.println("The max of three is: " + max);
}
}

请记得采纳哦!

2. java中两个字符串如何比较大小

int1
int2
long
t1="=
result
20131011"Integer;SimpleDateFormat("
有三种方法实现
第一种直接用字符串类的compareTo方法;
t1;
int
yyyyMMdd"
result小于0;
);
 .parseInt(t2);int
int1-int2;Date ;
sdf;d1
SimpleDateFormat
 .getTime();int
result
sdf;
注;Integer:
result等于0,则t1=t2.compareTo(t2);t2;
;Date
=
d2
= :
t2="
d1.getTime()-d2;=
第二种是把这个日期字符串转换成long;=
 .parse(t2);
=
 ;
String
t2:
 .parseInt(t1);
result
String
int
new
,则t1>
sdf
= ,则t1<
第三种是把日期字符串转换成整形int:result大于0.parse(t1);20131030"

热点内容
三位密码锁忘记密码如何重置 发布:2025-09-18 10:21:52 浏览:182
linux怎么编译c文件 发布:2025-09-18 09:55:16 浏览:302
python安装后无法运行 发布:2025-09-18 09:45:57 浏览:236
安卓手机怎么剪辑音乐 发布:2025-09-18 09:44:16 浏览:781
服务器地址修改在哪找 发布:2025-09-18 09:42:41 浏览:441
sntp服务器地址 发布:2025-09-18 09:28:36 浏览:552
phpunit 发布:2025-09-18 09:25:19 浏览:571
怎么改服务器的ip地址吗 发布:2025-09-18 09:24:33 浏览:12
编译703n固件 发布:2025-09-18 08:50:59 浏览:541
三星手机系统文件夹是哪个文件夹 发布:2025-09-18 08:48:45 浏览:284