Java数组选择排序

2023-05-16

Java数组选择排序

public static void main(String[] args) {
		// TODO Auto-generated method stub
		int a[]={4,3,5,8,3,9,13,7};
		int b[]=selectSort(a);
		show(b);
	}
	public static void show(int a[]){//定义显示数组方法
		for (int i = 0; i < a.length; i++) {
			System.out.println(a[i]);
		}
		
	}
	//选择排序
	public static int[] selectSort(int a[]){
			int minIndex;//定义最小值下标
			int temp;//定义存放数据的变量
		for (int i = 0; i < a.length-1; i++) {//定义遍历的趟数
			minIndex=i;
			for (int j =i+1; j <a.length; j++) {//定位从i到数组最后位置最小数下标
				if(a[j]<a[minIndex]){
					minIndex=j;
				}
			}
			if(minIndex!=i){
				temp=a[i];
				a[i]=a[minIndex];
				a[minIndex]=temp;
			}
		}
		return a;
	}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Java数组选择排序 的相关文章

随机推荐

  • linux操作redis

    Linux启动redis 1 为了保证原始redis config的准确性新建myRedis目录将redis config文件拷贝至myRedis下 root 64 linux1 bin ps ef grep redis root 1188
  • 经验呀,卡了我一个礼拜的经验

    今天处理html标签里的onclick功能的时候总是报错 xff1a Uncaught ReferenceError dosave is not defined 找了半天都没发现错在哪 xff0c 最后发现原来是我写法不对 xff0c 正确
  • onclick事件的传值 然后去执行ajax请求

    span class token punctuation span span class token function ajax span span class token punctuation span span class token
  • 牛客Java面试题

    请你说说Java和PHP的区别 xff1f 考察点 xff1a Java特性 参考回答 xff1a PHP暂时还不支持像Java那样JIT运行时编译热点代码 但是PHP具有opcache机制 能够把脚本对应的opcode缓存在内存 PHP7
  • 【mediasoup】demo与worker库交互channelRequest的实现

    cpp作者的mediasoup 比现在可以把worker作为一个库的要老一些 因此 与worker是以进程方式pipe通信的 D XTRANS soup mediasoup sfu cpp mediasoup WorkerAgent cpp
  • java面试题

    1 线程 线程创建方式继承Thread类和实现Runable接口 xff0c 重写run方法 使用callable和future创建线程 xff0c 使用线程池 外链图片转存失败 源站可能有防盗链机制 建议将图片保存下来直接上传 img r
  • 删除字符串中特定的字符

    通过字符串替换replace来实现特定字符串删除 span class token keyword package span com span class token punctuation span example span class
  • Git for Windows 国内下载站

    Git for Windows 国内下载站 Git for Windows 国内直接从官网 xff08 http git scm com download win xff09 下载比较困难 xff0c 需要翻墙 这里提供一个国内的下载站 x
  • You need to use a Theme.AppCompat theme (or descendant) with this activity

    报错 xff1a You need to use a Theme AppCompat theme or descendant with this activity 按照解释说明修改theme 初步推断再写Log v的时候报错应该和Log有关
  • 请计算1到100之内的所有质数

    请计算1到100之内的所有质数 JavaScript function hm3 var sum 61 0 得到一个数 for var i 61 2 i lt 61 100 i 43 43 var j 61 0 for var j 61 2
  • Java基础cmd窗口命令javac以及Java命令

    public static void main String args System out println 34 34 System out println 34 t1 显示客户信息 34 System out println 34 t2
  • eclipse输入天数计算周数

    计算周数 import java util Scanner public class Demo3 public static void main String args TODO Auto generated method stub Sca
  • 小测试,java的if条件语句和switch语句

    if条件语句和switch语句 import java util Scanner public class Demo4 public static void main String args TODO Auto generated meth
  • 求一个数的绝对值

    java求一个数的绝对值 public static void test3 Scanner sz 61 new Scanner System in System out println 34 请输入一个数 34 int a 61 sz ne
  • Java基础Test

    判断语句 1 打印 2 求两个浮点数之商 3 对一个数四舍五入取整 4 判断一个数是否为奇数 5 求一个数的绝对值 6 求两个数的最大值 7 求三个数的最大值 import java util Scanner public class Te
  • 【libuv】入门:queue work 的跨线程异步通信

    通过阅读2012年的uv book 入门 有中文版 Handles and Requests libuv works by the user expressing interest in particular events This is
  • 九九乘法表(java)

    九九乘法表 public class Cfb public static void main String args TODO Auto generated method stub printCfb public static void p
  • Java数组应用

    1 输出三位的水仙花数 2 输出n以内的数哪些数是质数 3 打印由 组成的等腰三角形 4 打印九九乘法表 5 用1元纸币兑换1分 xff0c 2分 xff0c 5分的硬币 xff0c 要求兑换50枚 问问尅有多少种组合 xff0c 每种组合
  • java的冒泡排序

    java的冒泡排序 TODO Auto generated method stub int a 61 11 10 5 7 9 3 5 2 6 bubbleSort a 调用排序方法 show a 调用现实方法 public static v
  • Java数组选择排序

    Java数组选择排序 public static void main String args TODO Auto generated method stub int a 61 4 3 5 8 3 9 13 7 int b 61 select