算法
来源:互联网 发布:手机淘宝的物流在哪看 编辑:程序博客网 时间:2024/05/22 06:05
/** 首尾互换* {1,2,3,4,5}*/int[] arr = {1,2,3,4,5,6,7,8,9};int tmp;for (int i=0,j=arr.length-1; i<j; i++,j--) {tmp = arr[i];arr[i] = arr[j];arr[j] = tmp;}System.out.println(Arrays.toString(arr));
/** 排序* int a=3, b=2, c=1* 按照从小到大排序后的顺序为:1 2 3 */int a=3, b=2, c=1;if(a>b){int temp = a;a = b;b = temp;}if(a>c){int temp = a;a = c;c = temp;}if(b>c){int temp = b;b = c;c = temp;}System.out.println(a+" "+b+" "+c);
/** 奇数放左边,偶数放右边*/int[] arr = {1,2,3,4,5,6,7,8,9};int count = 0;int tmp;for (int i=0; i<arr.length; i++) {if (arr[i]%2!=0) {tmp = arr[count];arr[count] = arr[i];arr[i] = tmp;count++;}}System.out.println(Arrays.toString(arr));
阅读全文
0 0
- 算法
- 算法
- 算法
- 算法
- 算法
- 算法
- 算法
- 算法
- 算法
- 算法
- 算法
- 算法
- 算法
- 算法
- 算法
- 算法
- 算法
- 算法
- HDU 1079 Calendar Game
- windows下Mysql多实例安装说明
- android,安卓,TabLayout + ViewPager + Fragment
- 泛型,java,就业班
- JAVA编译和运行环境的配置
- 算法
- leetcode --21. Merge Two Sorted Lists
- 123123
- Andrid弹框开源
- 线段树基本入门知识
- webpack打包字体路径不对问题
- 外部耦合
- ROS(indigo) 下 利用UDP跟电机驱动器通讯驱动电机运动
- 'xxx' declared as a 'virtual' field ----一个奇怪的C++bug