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

熱點內容
海克斯康三次元如何編程循環測量 瀏覽:518
app無法下載是為什麼蘋果手機 瀏覽:518
右擊此電腦管理找不到此文件 瀏覽:264
圖像文件格式百科 瀏覽:523
沒有網路怎麼定位 瀏覽:972
剪切到優盤文件找不到了 瀏覽:764
電腦管家的文件名 瀏覽:910
如何將掃描文件轉換為電子版 瀏覽:4
u盤的h246文件怎麼播放 瀏覽:203
如何用阿里雲伺服器學習資料庫 瀏覽:84
華為文件管理找不到下載文件 瀏覽:409
word模板dot的使用 瀏覽:466
春節車找人app哪個好 瀏覽:618
文件管理電腦找不到了怎麼辦 瀏覽:516
如何改變app圖標圖片 瀏覽:767
什麼是大數據結構的最低層 瀏覽:575
pdf文件給對方後期改密碼收回 瀏覽:295
word2010怎麼畫箭頭 瀏覽:184
win10的自動備份文件在哪個目錄 瀏覽:843
文件夾打包成jar 瀏覽:456

友情鏈接