用eclipse运行java:用键盘输入数据后排序
- 提问者网友:姑娘长的好罪过
- 2021-05-09 15:22
- 五星知识达人网友:轮獄道
- 2021-05-09 16:17
能详细的说下 吗 或者联系我 详谈
- 1楼网友:愁杀梦里人
- 2021-05-09 18:18
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer;
public class Bubble { public static void main(String[] args) { String s; String str[] = new String[10]; int a[] = new int[10]; int i = 0; BufferedReader bufferedReader = new BufferedReader( new InputStreamReader(System.in)); try { s = bufferedReader.readLine(); StringTokenizer stringTokenizer = new StringTokenizer(s, " "); while (stringTokenizer.hasMoreTokens()) { str[i] = stringTokenizer.nextToken(); i++; } for (i = 0; i < 10; i++) try { a[i] = Integer.parseInt(str[i]); // System.out.print(a[i] + " "); } catch (NumberFormatException e) { } bufferedReader.close(); } catch (IOException e) { } for (i = 0; i < a.length - 1; i++) { for (int j = 0; j < a.length - i - 1; j++) { if (a[j] > a[j + 1]) { a[j] = a[j] + a[j + 1]; a[j + 1] = a[j] - a[j + 1]; a[j] = a[j] - a[j + 1]; } } } for (i = 0; i < a.length; i++) System.out.print(a[i] + " ");
}
}
- 2楼网友:愁杀梦里人
- 2021-05-09 17:41
冒个泡就好了
for(int i=0;i <=集合大小-1; i++){
for(int j=0; j<集合大小-i-1; j++){
int temp = arr[j];
if(arr[j]>arr[j+1]){
arr[j]=arr[j+1];
arr[j+1]=temp;
}
}
}