Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Java SE 综合讨论区  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 冒泡排序算法的一个问题.进来看看
lsqily82





发贴: 6
积分: 0
于 2006-02-23 22:49 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
public class Bubble
{
  public static void main(String args[])
  {
  
    int array[]= {55,2,6,4,32,12,-9,73,26,37};
    System.out.println("数据原始顺序:"+args[0]);
    
   for (int i=0;i<array.length;i++)
   {
     System.out.print(args[i]+"\t");
   }
   Bubble b=new Bubble();
   int[] result =b.bubble(array);
    
    
     System.out.println("\n\n排序后:");
     for(int i=0;i<result.length;i++)
     {
       System.out.print(result[i]+"\t");
     }
     }
    public int[] bubble(int a[])
    {
      int temp,size=a.length;//外层循环
      for (int i=size-1;i>=1;i--)
      {
        boolean end =true;
        //内层循环
        for(int j=0;j<i;j++)
        {
          if(a[j]>a[j+1])
          {
            temp=a[j];
            a[j]=a[j+1];
            a[j+1]=temp;
            end =false;
          }
        }
        if(end==true){
        break;
      }
    }
      return a;
    }
       
    }
我这样编译可以,但我不知道要怎么写才能实现键盘输入一组数字.然后输出排序后的结果,请各位高手帮忙一下.不胜感谢.我是新手,



作者 Re:冒泡排序算法的一个问题.进来看看 [Re:lsqily82]
whiye





发贴: 8
积分: 0
于 2006-02-25 09:31 user profilesend a private message to usersend email to whiyesearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
An easy question! 找本Java IO的书看一下的话就应该会了,好多书上都有这种例子的



作者 Re:冒泡排序算法的一个问题.进来看看 [Re:lsqily82]
tzutolin



版主


发贴: 581
积分: 65
于 2006-02-25 10:03 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
你可以將輸入以 main 的參數形式傳入, 或者是直接用 Swing 元件的 getText, 然後用 StringTokenizer 取得輸入.


作者 Re:冒泡排序算法的一个问题.进来看看 [Re:lsqily82]
mliwng





发贴: 6
积分: 0
于 2006-03-19 19:02 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
for(i=0;i<10;i++)
{
BufferedReader cin = new BufferedReader( new InputStreamReader( System.in ) );
String s = cin.readLine();
array[i] = Integer.parseInt( s );
}
这样可以从键盘输入数据了




作者 Re:冒泡排序算法的一个问题.进来看看 [Re:lsqily82]
jackyangf





发贴: 58
积分: 1
于 2006-03-20 17:50 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
跟着学习!谢谢


作者 Re:冒泡排序算法的一个问题.进来看看 [Re:lsqily82]
heartache





发贴: 59
积分: 0
于 2006-03-23 14:44 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
晕,不是有个自动排序的方法吗 ?


作者 Re:冒泡排序算法的一个问题.进来看看 [Re:lsqily82]
j2eesir





发贴: 7
积分: 0
于 2006-03-24 10:05 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
LZ的程序有保持C的风格,建议从面向对象的角度进行。
学JAVA,就要从Java的角度考虑问题。:)




flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923