當前位置:首頁 » 編程語言 » 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"

熱點內容
androiddialog創建 發布:2025-08-28 13:09:26 瀏覽:949
初級伺服器是指什麼 發布:2025-08-28 13:08:39 瀏覽:99
微軟dns伺服器地址 發布:2025-08-28 13:07:20 瀏覽:605
2013款榮放頂配有哪些配置 發布:2025-08-28 13:05:32 瀏覽:665
dedecmssql注入漏洞 發布:2025-08-28 12:54:27 瀏覽:396
dash官網搭建伺服器 發布:2025-08-28 12:45:17 瀏覽:745
html上傳圖片模板 發布:2025-08-28 12:41:30 瀏覽:998
安卓手機怎麼設置默認安裝軟體 發布:2025-08-28 12:32:57 瀏覽:910
演算法團隊6 發布:2025-08-28 12:31:23 瀏覽:18
簡訊鈴聲在哪個文件夾 發布:2025-08-28 12:28:35 瀏覽:346