Java排序之冒泡法

来源:互联网 发布:最高效判断质数的算法 编辑:程序博客网 时间:2024/06/05 19:53
package com.tuyao.paixu;


import java.util.Scanner;


public class Maopao
{
   public static void main(String args[])
   {
  System.out.println("请输入排序数字的个数:");
  Scanner scint=new Scanner(System.in);
  int geshu=scint.nextInt();
  
  Scanner sc=new Scanner(System.in);
 
  int [] a = new int[geshu];
  int temp;
 
  for(int i=0;i<geshu;i++)
  {
System.out.println("请输入数字:");
    a[i]=sc.nextInt();
  }
  
  for(int i=0;i<geshu-1;i++)
  {   
  for(int j=0;j<geshu-1-i;j++)
  {
  if(a[j]>a[j+1])
  {
  temp=a[j+1];
  a[j+1]=a[j];
  a[j]=temp;  
  }
  
  }
  
  }
   
  for(int i=0;i<geshu;i++)
  {
  System.out.print(a[i]+" ");
  }
  
  
 
   }

}


本人非常喜欢做开发,自己做的有关于互联网学习的网站-学亦知网站:www.xueyizhi.com,对应的论坛:bbs.xueyizhi.com,技术QQ群:175603095,非常欢迎大家过来一起学习!

1 0
原创粉丝点击