導航:首頁 > 編程語言 > 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整型比較相關的資料

熱點內容
谷歌瀏覽器的debug調試工具 瀏覽:163
哪個數控編程是免費的 瀏覽:368
蘋果7plus玫瑰金報價 瀏覽:800
杭州自行車系統微信號 瀏覽:352
網路語偷豬是什麼意思 瀏覽:309
三星i9300線刷教程圖解 瀏覽:248
編程競賽特訓哪裡好 瀏覽:28
提取驅動文件 瀏覽:102
如何壓縮wps文件 瀏覽:314
ps轉ico文件 瀏覽:303
無編程計算器是指哪些 瀏覽:852
jquery伺服器返回json數據格式 瀏覽:375
pl0編譯程序文本c版本 瀏覽:687
cocos2djs開發 瀏覽:124
怎麼取消蘋果電腦密碼怎麼設置 瀏覽:950
word2013序列號 瀏覽:462
fu是什麼海淘網站 瀏覽:620
u盤和充電器數據線哪個好 瀏覽:969
中走絲下載什麼編程軟體 瀏覽:643
win10創建讀取文件 瀏覽:211

友情鏈接