import java.util.Scanner; public class Test { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int[] a = new int[3]; a[0] = scan.nextInt(); a[1] = scan.nextInt(); a[2] = scan.nextInt(); sort(a); show(a); } public static void sort(int[] a){ //冒泡排序 int n = a.length; for (int i = n; i > 1; i--){ for (int j = 0; j < i-1; j++) { if ( a[j] > a[j+1]) { int x = a[j]; a[j] = a[j+1]; a[j+1] = x; } } } } public static void show(int[] a){ for (int i = 0; i < a.length; i++) { System.out.print(a[i]+" "); } System.out.println(); }}
import java.util.Scanner; public class SortNum { public static void main(String[] args) { int a, b, c; int t; //临时变量 Scanner input = new Scanner(System.in); System.out.println("请输入a的值:"); a = input.nextInt(); System.out.println("请输入b的值:"); b = input.nextInt(); System.out.println("请输入c的值:"); c = input.nextInt(); System.out.println("排序前" + a + " " + b + " " + c); if (a > b) { t = a; a = b; b = t; } if (a > c) { t = a; a = c; c = t; } if (b > c) { t = b; b = c; c = t; } System.out.println("排序后" + a + " " + b + " " + c); } }
import java.util.Scanner;
public class Test { public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int[] a = new int[3];
a[0] = scan.nextInt();
a[1] = scan.nextInt();
a[2] = scan.nextInt();
sort(a);
show(a);
}
public static void sort(int[] a){ //冒泡排序
int n = a.length;
for (int i = n; i > 1; i--){
for (int j = 0; j < i-1; j++) {
if ( a[j] > a[j+1]) {
int x = a[j];
a[j] = a[j+1];
a[j+1] = x;
}
}
}
}
public static void show(int[] a){
for (int i = 0; i < a.length; i++) {
System.out.print(a[i]+" ");
}
System.out.println();
}}
public class SortNum {
public static void main(String[] args) {
int a, b, c;
int t; //临时变量
Scanner input = new Scanner(System.in);
System.out.println("请输入a的值:");
a = input.nextInt();
System.out.println("请输入b的值:");
b = input.nextInt();
System.out.println("请输入c的值:");
c = input.nextInt();
System.out.println("排序前" + a + " " + b + " " + c);
if (a > b) {
t = a;
a = b;
b = t;
}
if (a > c) {
t = a;
a = c;
c = t;
}
if (b > c) {
t = b;
b = c;
c = t;
}
System.out.println("排序后" + a + " " + b + " " + c); }
}