freepeople性欧美熟妇, 色戒完整版无删减158分钟hd, 无码精品国产vα在线观看DVD, 丰满少妇伦精品无码专区在线观看,艾栗栗与纹身男宾馆3p50分钟,国产AV片在线观看,黑人与美女高潮,18岁女RAPPERDISSSUBS,国产手机在机看影片

正文內(nèi)容

java經(jīng)典算法40題-資料下載頁

2025-03-24 04:57本頁面
  

【正文】 myarr[k]=temp。 } ()。 for (int k=1。k=10。k++) (myarr[k]+,)。 myarr[11]=(1000)。 for(int k=1。k=10。k++) if(myarr[k]myarr[11]) { temp=myarr[11]。 for(int j=11。j=k+1。j) myarr[j]=myarr[j1]。 myarr[k]=temp。 } ()。 for (int k=1。k=11。k++) (myarr[k]+,)。 }}【程序31】 題目:將一個數(shù)組逆序輸出。 程序分析:用第一個與最后一個交換。 其實,用循環(huán)控制變量更簡單: for(int k=11。k=1。k) (myarr[k]+,)。【程序32】 題目:取一個整數(shù)a從右端開始的4~7位。 程序分析:可以這樣考慮: (1)先使a右移4位。 (2)設(shè)置一個低4位全為1,其余全為0的數(shù)??捎脋(~0 4) (3)將上面二者進行amp。運算。 public class Ex32 { public static void main(String[] args) { int a=0。 long b=18745678。 a=(int) (b % (10,7)/(10, 3))。 (a)。 } }【程序33】 題目:打印出楊輝三角形(要求打印出10行如下圖) : 1 1 1 1 2 1 1 3 3 1 1 4 6 4 1 1 5 10 10 5 1 public class Ex33 { public static void main(String args[]){ int i,j。 int a[][]。 a=new int[8][8]。 for(i=0。i8。i++){ a[i][i]=1。 a[i][0]=1。 } for(i=2。i8。i++){ for(j=1。j=i1。j++){ a[i][j]=a[i1][j1]+a[i1][j]。 } } for(i=0。i8。i++){ for(j=0。ji。j++){ ( +a[i][j])。 } ()。 } }}【程序34】 題目:輸入3個數(shù)a,b,c,按大小順序輸出。 :利用指針方法。 public class Ex34 { public static void main(String[] args) { int []arrays = {800,56,500}。 for(int i=。i=0。) { for(int j=0。ji。j++) { if(arrays[j]arrays[j+1]) { int temp=arrays[j]。 arrays[j]=arrays[j+1]。 arrays[j+1]=temp。 } } } for(int n=0。n。n++) (arrays[n])。 } }【程序35】 題目:輸入數(shù)組,最大的與第一個元素交換,最小的與最后一個元素交換,輸出數(shù)組。 import .*。 public class Ex35 {public static void main(String[] args) { int i, min, max, n, temp1, temp2。 int a[]。 (輸入數(shù)組的長度:)。 Scanner keyboard = new Scanner()。 n = ()。 a = new int[n]。 for (i = 0。 i n。 i++) { (輸入第 + (i + 1) + 個數(shù)據(jù))。 a[i] = ()。 } //以上是輸入整個數(shù)組max = 0。 min = 0。 //設(shè)置兩個標(biāo)志,開始都指向第一個數(shù)for (i = 1。 i n。 i++) { if (a[i] a[max]) max = i。 //遍歷數(shù)組,如果大于a[max],就把他的數(shù)組下標(biāo)賦給maxif (a[i] a[min]) min = i。 //同上,如果小于a[min],就把他的數(shù)組下標(biāo)賦給min} //以上for循環(huán)找到最大值和最小值,max是最大值的下標(biāo),min是最小值的下標(biāo)temp1 = a[0]。 temp2 = a[min]。 //這兩個temp只是為了在交換時使用a[0] = a[max]。 a[max] = temp1。 //首先交換a[0]和最大值a[max]if (min != 0) { //如果最小值不是a[0],執(zhí)行下面a[min] = a[n 1]。 a[n 1] = temp2。 //交換a[min]和a[n1]} else { //如果最小值是a[0],執(zhí)行下面a[max] = a[n 1]。 a[n 1] = temp1。 } for (i = 0。 i n。 i++) { //輸出數(shù)組(a[i] + )。 } }}【程序36】 題目:有n個整數(shù),使其前面各數(shù)順序向后移m個位置,最后m個數(shù)變成最前面的m個數(shù) 【程序37】 題目:有n個人圍成一圈,順序排號。從第一個人開始報數(shù)(從1到3報數(shù)),凡報到3的人退出圈子,問最后留下的是原來第幾號的那位。 import 。public class Ex37 { public static void main(String[] args) { Scanner s = new Scanner()。 int n = ()。 boolean[] arr = new boolean[n]。 for(int i=0。 i。 i++) { arr[i] = true。//下標(biāo)為TRUE時說明還在圈里 } int leftCount = n。 int countNum = 0。 int index = 0。 while(leftCount 1) { if(arr[index] == true) {//當(dāng)在圈里時 countNum ++。 //報數(shù)遞加 if(countNum == 3) {//報道3時 countNum =0。//從零開始繼續(xù)報數(shù) arr[index] = false。//此人退出圈子 leftCount 。//剩余人數(shù)減一 } } index ++。//每報一次數(shù),下標(biāo)加一 if(index == n) {//是循環(huán)數(shù)數(shù),當(dāng)下標(biāo)大于n時,說明已經(jīng)數(shù)了一圈, index = 0。//將下標(biāo)設(shè)為零重新開始。 } } for(int i=0。 in。 i++) { if(arr[i] == true) { (i)。 } } }}【程序38】 題目:寫一個函數(shù),求一個字符串的長度,在main函數(shù)中輸入字符串,并輸出其長度。 import 。public class Ex38 {public static void main(String [] args){ Scanner s = new Scanner()。 (請輸入一個字符串)。 String mys= ()。 (str_len(mys))。} public static int str_len(String x) { return ()。 }} 題目:編寫一個函數(shù),輸入n為偶數(shù)時,調(diào)用函數(shù)求1/2+1/4+...+1/n,當(dāng)輸入n為奇數(shù)時,調(diào)用函數(shù)1/1+1/3+...+1/n【程序39】 題目:字符串排序。 import .*。 public class test{ public static void main(String[] args) { ArrayListString list=new ArrayListString()。 (010101)。 (010003)。 (010201)。 (list)。 for(int i=0。i()。i++){ ((i))。 } } }【程序40】 題目:海灘上有一堆桃子,五只猴子來分。第一只猴子把這堆桃子憑據(jù)分為五份,多了一個,這只猴子把多的一個扔入海中,拿走了一份。第二只猴子把剩下的桃子又平均分成五份,又多了一個,它同樣把多的一個扔入海中,拿走了一份,第三、第四、第五只猴子都是這樣做的,問海灘上原來最少有多少個桃子? public class Dg {static int ts=0。//桃子總數(shù)int fs=1。//記錄分的次數(shù)static int hs=5。//猴子數(shù)...int tsscope=5000。//.public int fT(int t){if(t==tsscope){//當(dāng)桃子數(shù)到了最大的取值范圍時取消遞歸(結(jié)束)。return 0。}else{if((t1)%hs==0 amp。amp。 fs =hs){if(fs==hs){(桃子數(shù) = +ts + 時滿足分桃條件)。} fs+=1。 return fT((t1)/5*4)。// 返回猴子拿走一份后的剩下的總數(shù)}else{//沒滿足條件fs=1。//分的次數(shù)重置為1return fT(ts+=1)。//桃子數(shù)加+1}}}public static void main(String[] args) {new Dg().fT(0)。}}
點擊復(fù)制文檔內(nèi)容
研究報告相關(guān)推薦
文庫吧 www.dybbs8.com
備案圖鄂ICP備17016276號-1