導航:首頁 > 編程語言 > java整型比較

java整型比較

發布時間:2023-06-12 00:24:24

㈠ 在java中怎麼比較三個整數大小例如(a , b, c);並從小到大輸出

用冒泡排序,對三個數字按照由小到大進行排掘配序。以23、11、17為例,代碼如下:

import java.util.Scanner;

public class woo {

static int[] bubbleSort(int[] date) {

boolean isSwap;

for(int j = 1; j < date.length; j++) {

isSwap = false;

for(int i = 0; i < date.length - j; i++) {

if(date[i] > date[i+1]) {

date[i] = date[i] ^ date[i+1];

date[i+1] = date[i] ^ date[i+1];

date[i] = date[i] ^ date[i+1];

isSwap = true;

}

}

if(isSwap == false)

break;

}

return date;

}

public static void main(String args[]) {

int date[] = new int[3];

System.out.println("輸入三個整數:");

Scanner num = new Scanner(System.in);

for(int i = 0;i < date.length; i++)

date[i] = num.nextInt();

date = bubbleSort(date);

for(int count = 0; count < date.length; count++)

System.out.print(date[count] +" ");

System.out.println("");

}

}

(1)java整型比較擴展閱讀

通常排序演算法,可以分為兩大類。

非線性時間比較類排序:通過比較來決定元素間的相對次序,由於判塌指其時間復雜度不能突破O(nlogn),因此稱為非線性時間比較類排序。包括交換排序、插入排序、選擇排序、歸並排序。

線性時間非比衫信較類排序:不通過比較來決定元素間的相對次序,它可以突破基於比較排序的時間下界,以線性時間運行,因此稱為線性時間非比較類排序。包括計數排序、桶排序、計數排序。

㈡ 在java中怎麼比較三個整數大小例如(a,b,c

public class Sort {

public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("請依次輸入3個數字");
int a = scanner.nextInt();
int b = scanner.nextInt();
int c = scanner.nextInt();
if( b > a){
int t = 0;
t = a;
a = b;
b = t;
}
if( c > a){
int t =0;
t = a;
a = c;
c = t;
}
if( c > b){
int t = 0;
t = c;
c = b;
b = t;
}

System.out.println("a = "+ a + " b= " + b + " c= " + c );
}

}

㈢ java中長整型和整型的區別

相同點:
兩者都是整數
不同點:
長整形取值范圍比整型取值范圍大。
長整形最大值:9223372036854775807
整型最大值:2147483647

㈣ 如何用Java比較兩個整數的大小

publicclassHello{
publicstaticvoidmain(String[]args){
System.out.println(getMax(2,10));
}
publicstaticintgetMax(inta,intb){
returna>b?a:b;
}
}

閱讀全文

與java整型比較相關的資料

熱點內容
ps中文件格式不屬於矢量圖的是 瀏覽:148
U盤緩存文件夾 瀏覽:941
視頻響應式js 瀏覽:191
編程模型怎麼看圖 瀏覽:177
相機7500打A檔數據調多少 瀏覽:182
單引號雙引號js 瀏覽:924
該文件包含違規內容是什麼意思 瀏覽:926
maya臉部捕捉教程 瀏覽:762
聯通app如何看寬頻網速 瀏覽:605
maccs6打不開raw文件格式 瀏覽:730
UG90升級包360雲盤 瀏覽:831
dnf念帝90版本寵物推薦 瀏覽:777
引用css文件到html網頁里方法 瀏覽:217
天之眼導航地圖怎麼升級 瀏覽:934
word文件修改後怎麼重新生成目錄 瀏覽:973
win2008iis上傳文件大小 瀏覽:948
js怎麼取3cs的值 瀏覽:823
發文件到郵箱怎麼發送失敗是怎麼回事 瀏覽:365
我和微信的故事盜號 瀏覽:836
網路審計設備品牌 瀏覽:335

友情鏈接