冒泡排序
package studyjava; public class maopao { public static void main(String[] args) { int[] a={3,6,2,8,54,1,34}; sort(a); for(int i=0;i<a.length;i++) { System.out.println(a[i]); } } static void sort(int[] a) { int length=a.length; int temp; int i,j; for(j=length-1;j<length;j--) { for(i=0;i<j;i++) { if(a[i]>a[i+1]) { temp=a[i+1]; a[i+1]=a[i]; a[i]=temp; } } } } }
JAVA实现字符串反转
package studyjava; public class maopao { public static void main(String[] args) { String str="I love java"; StringBuffer sb=reverse(str); System.out.print(sb.toString()); } public static StringBuffer reverse(String s) { String[] str= s.split(" "); StringBuffer sb=new StringBuffer(); for(int i=str.length-1;i>=0;i--) { sb.append(str[i]); sb.append(" "); } return sb; } }