Java face question 2

Source: Internet
Author: User

1. Bubble sort

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. Printing triangles

 public  static  void   Test () { int  row = 5;  for  (int  i = 1; i<=row; i++ for  (int J =0;j<row-i;j++ ");  for  (int  J =0;J<2*I-1;J++
     
       "#" 
      
     
    #   ###  ##### ################

3. Detect if a string is a numeric component

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

 

4. Date formatting

public static String datefomate (date date) {SimpleDateFormat SDF = new SimpleDateFormat ("Yyyy/mm/dd"); return Sdf.format ( date);}

  

Java face question 2

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.