第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

用戶輸入的 Int 值的冒泡排序數(shù)組

用戶輸入的 Int 值的冒泡排序數(shù)組

侃侃爾雅 2021-07-08 10:06:35
我正在嘗試解決此代碼中遇到的兩個(gè)問題。首先,我想將我的整數(shù)輸入設(shè)置為最大值 100,其次我試圖獲取輸入的整數(shù)數(shù)組并按絕對(duì)值對(duì)它們進(jìn)行排序。所以如果用戶使用這個(gè)程序,我希望他們只能輸入 99 來表示他們想要排序的整數(shù)數(shù)量。當(dāng)它最終被排序而不是降序或升序時(shí),我希望它是這樣的;-1,2,-6,10,-20。 public static void main(String args[]){   int n, i, j, temp;   int arr[] = new int[50];   Scanner scan = new Scanner(System.in);   //Input area for user data, setting the number of integers to sort   System.out.print("Enter Total Number of Integers you would like to sort : ");   n = scan.nextInt();   for (n=0, n < 100, n++)   {   }   //Input area for user data, asking user to input the ints into an array for sorting   System.out.print("Enter " +n+ " Numbers : ");   for(i=0; i<n; i++)   {       arr[i] = scan.nextInt();   }   // Sorting Array using Bubble Sort Technique   for(i=0; i<(n-1); i++)   {       for(j=0; j<(n-i-1); j++)       {           if(arr[j] > arr[j+1])           {               temp = arr[j];               arr[j] = arr[j+1];               arr[j+1] = temp;           }       }   }   // Command line output from user, sorted by absolute value         System.out.print("Sorted List : \n");   for(i=0; i<n; i++)   {       System.out.print(java.lang.Math.abs(arr[i])+ "  ");   } }}
查看完整描述

1 回答

  • 1 回答
  • 0 關(guān)注
  • 195 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)