java - Java / Java EE
定义一个一维整型数组,其中存储随机生成的0-9999之间的100个整数,分别采用简单选择排序和冒泡排序方法对它们进行排序,最后输出排序后的结果。
没考虑效率,你看下吧!冒泡的 import java.util.Random; public class SortResult { public int[] getMaopao(int[] b) { Random rnd=new Random(); for(int i=0;i<b.length;i++) { b[i]=rnd.nextInt(10000); } for(int i=0;i<b.length;i++) { for(int j=1;j<b.length;j++) { if(b[j]<b[j-1]) { int temp=b[j]; b[j]=b[j-1]; b[j-1]=temp; } } } return b; } public static void main(String args[]) { int[] a=new int[100]; SortResult sr=new SortResult(); sr.getMaopao(a); for(int i=0;i<a.length;i++) { System.out.print(a[i]+" "); } } }引用 没考虑效率,你看下吧!冒泡的 import java.util.Random; public class SortResult { public int[] getMaopao(int[] b) { Random rnd=new Random(); for(int i=0;i<b.length;i++) { b[i]=rnd.nextInt(10000); } …… 这个冒泡的算法应该可以了,太久不写算法了,手生了
相关问答:
<?xml version="1.0" encoding="utf-8" ?> - <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical&q ......
为什么HTML以及一些其它标签会显示一些特定表现形式呢?如HTML中的换行标签<BR/>在底层是怎样实现的呢?现实的原理是什么呢 去W3C官方网站上,看看吧!我想一看你就明白了 我猜和编译原理有关,浏览器里可 ......
org.apache.jasper.JasperException: Unable to compile class for JSP: An error occurred at line: 52 in the jsp file: /vip_info.jsp ÕË cannot be resolved 49: <table border="1& ......
大家好,我在JSP的初学者,在编程中遇到了一个问题: <jsp:useBean id="accountBiz" class="bank.AccountBiz" scope="application"> 这个标签中application和sessi ......