冒泡跟扫描共用
package lianxi; import java.util.Scanner; public class maopao { Scanner scan =new Scanner(System.in); System.out.print("请输入:"); String usename =scan.nextLine(); int c[]=new int []{12,34,97,23,67,98,56,7}; for(int j=0;j<c.length-1;j++){ for(int i=0;i<c.length-1;i++){ if (c[i]>c[i+1]){ int b=c[i]; c[i]=c[i+1]; c[i+1]=b; } } for (int t:c){ } } if(usename.equals("最大的数")){ System.out.print(c[c.length-1]); } else if(usename.equals("最小的数")){ System.out.println(c[0]); } } }