- class Slef_Tool1 {
- public static void main(String[] args) {
- int[] arr={13,78,33,66,22,8,10};
- Tools.revArr(arr);
- System.out.println();
- Tools.sortArr(arr);
- System.out.println();
- Tools.getMutiplyTable();
- }
- }
- class Tools {
- private Tools(){}
- //打印乘法口诀表
- private static void printMutiplyTable(){
- for (int i=1;i<=9 ;i++ ){
- for (int j=1;j<=i ;j++ ){
- System.out.print(i+"*"+j+"="+i*j+"\t");
- }
- System.out.println();
- }
- }
- public static void getMutiplyTable(){
- printMutiplyTable();
- }
- //翻转数组
- public static void revArr(int[] arr){
- for (int i=0;i<arr.length/2 ;i++ ){
- int temp=0;
- temp=arr[i];
- arr[i]=arr[arr.length-i-1];
- arr[arr.length-i-1]=arr[i];
- }
- for (int i=0;i<arr.length ;i++ ){
- System.out.print(arr[i]+"\t");
- }
- }
- //数组冒泡排序
- public static void sortArr(int[] arr){
- for (int i=1;i<arr.length ;i++ ){ //TheNumberOfCompare;
- for (int j=0;j<arr.length-i ;j++ ){
- if (arr[j]<arr[j+1]){
- arr[j]=arr[j]+arr[j+1];
- arr[j+1]=arr[j]-arr[j+1];
- arr[j]=arr[j]-arr[j+1];
- }
- }
- }
- for (int i=0;i<arr.length ;i++ ){
- System.out.print(arr[i]+"\t");
- }
- }
- }
复制代码 |
|