java面试题2

1.冒泡排序

public static void test(){
		int[] array = new int[]{1,4,5,8,9,34,4,32,65};
		int tmp;
		for(int i=0 ;i< array.length;i++){
			for(int j = i+1;j<array.length;j++){
				if(array[j]>array[i]){
					tmp = array[i];
					array[i]=array[j];
					array[j]=tmp;
				}
			}
		}
		for(int i : array){
			System.out.print(i+">");
		}
	}

 2.打印三角形

public static void test(){
        int row = 5;
        for(int i = 1 ; i<=row ; i++){
            for(int j =0;j<row-i;j++){
                System.out.print(" ");
            }
            for(int j =0;j<2*i-1;j++){
                System.out.print("#");
            }
            System.out.println();
        }
    }
    #
   ###
  #####
 #######
#########

3.检测字符串是否为数字构成

public static boolean isNumByRegex(String s){
		Pattern p = Pattern.compile("[0-9]+");
		return p.matcher(s).matches();
	}

 

4.日期格式化

public static String dateFomate(Date date){
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
		return sdf.format(date);
	}

  

原文地址:https://www.cnblogs.com/lakeslove/p/7354371.html