package wzybf; import java.util.Arrays; public class IntSort { // 对两个数进行排序输出 public static void sort(int a, int b) { if (a > b) { System.out.println(b + " " + a); } else { System.out.println(a + " " + b); } } // 对三个数进行排序输出 public static void sort(int a, int b, int c) { if (a > b) { int temp = a; a = b; b = temp; } if (a > c) { int temp = a; a = c; c = temp; } if (b > c) { int temp = b; b = c; c = temp; } System.out.println(a + " " + b + " " + c); } // 对数组进行排序输出 public static void sort(int[] arr) { Arrays.sort(arr); for (int num : arr) { System.out.print(num + " "); } System.out.println(); } public static void main(String[] args) { IntSort.sort(5, 3); IntSort.sort(2, 4, 1); IntSort.sort(new int[]{5, 4, 6, 2, 8, 1}); } }说明定义的各类以及创建各对象的意义,各个类之间的继承关系;
时间: 2024-02-10 17:33:27 浏览: 35

java代码-import java.util.Scanner;

该代码中只定义了一个类IntSort,没有创建其他类的对象,也没有类之间的继承关系。
IntSort类有三个方法,sort(int a, int b)、sort(int a, int b, int c)和sort(int[] arr),分别用于对两个数、三个数和一个数组进行排序输出。
该类的主方法main()演示了如何使用这三个方法对数值进行排序输出。
阅读全文
相关推荐
















