import?java.util.*;
成都創(chuàng)新互聯(lián)是專業(yè)的興安盟網(wǎng)站建設(shè)公司,興安盟接單;提供做網(wǎng)站、網(wǎng)站建設(shè),網(wǎng)頁設(shè)計(jì),網(wǎng)站設(shè)計(jì),建網(wǎng)站,PHP網(wǎng)站建設(shè)等專業(yè)做網(wǎng)站服務(wù);采用PHP框架,可快速的進(jìn)行興安盟網(wǎng)站開發(fā)網(wǎng)頁制作和功能擴(kuò)展;專業(yè)做搜索引擎喜愛的網(wǎng)站,專業(yè)的做網(wǎng)站團(tuán)隊(duì),希望更多企業(yè)前來合作!
2?
3?public?class?Sa?{
4?public?static?void?main(String[]?args)?{
5?????StackObject?s?=?new?Stack();
6?????int[]?a?=?{1,?2,?3,?4,?5};
7?????for?(int?i?=?0;?i??a.length;?i++)?{
8?????????s.push(a[i]);
9?????}
10?????int?j?=?0;
11?????while(!s.empty())?{
12????????腔銀?a[j]?=?(int)s.pop();
13????????型拍?j++;
14?????}
15?
16???伍租宴??for(int?i?=?0;?i??a.length;?i++)?{
17?????????System.out.print(a[i]?+?"?");
18?
19?????}
20?????System.out.println("");
21?
22?}
23?}
public?class?SwapDemo{??
public?static?void?main(String[]?args){??
int?[]?a?=?new?int[]{??
//Math.random()?a?pseudorandom?double?greater?than?or?equal?to?0.0?and?less?than?1.0??
(int)(Math.random()?*?1000),??
(int)(Math.random()?*?1000),??
(int)(Math.random()?*?1000),??
(int)(Math.random()?*?1000),??????????????????????????
(int)(Math.random()?*?1000),??????????????????????????
(int)(Math.random()?*?1000),??????????????????????????
(int)(Math.random()?*?1000)???????????????????????????????????????????????????????????????????????
};????
System.out.println(Arrays.toString(a));??
喚盯臘??swap(a);??
System.out.println(Arrays.toString(a));???????
}??
public?static?void?swap(int?a[]){??
則御??????int?len?=?a.length;??
和滑????for(int?i=0;ilen/2;i++){??
int?tmp?=?a[i];??
a[i]?=?a[len-1-i];??
a[len-1-i]?=?tmp;??
}??
}??
}
第一個(gè)元素和最后一個(gè)元素交換鬧簡位置,第二個(gè)元拿沖素和倒數(shù)第二個(gè)元素交換消彎殲位置,依次置換。
代碼:
結(jié)果: