Java常用工具類練習

2021-09-05 12:59:14 字數 1278 閱讀 3470

public class testcheckusername 

//長度大於6,

if(username.length()<=6)

//不能有數字

for(int i=0;i='0')

} system.out.println("使用者名稱符合要求");

}}

public class teststringconvert  catch (parseexception e) 

//輸出結果

system.out.println(age+" "+score+" "+enterdate);

}}

//定義訊號燈列舉 

public enum signal

public class testsignal

}}

4.編寫遞迴演算法程式:一列數的規則如下: 1、1、2、3、5、8、13、21、34… 求數列的第40位數是多少。

public class testsum

public static long sum(int n) else if (n == 1 || n == 2) else

}}

public class testdirectory 

public static void showtree(file file,int level);

system.out.println(searchrecursive(array, 0, array.length - 1, 20));

} /**

* 執行遞迴二分查詢,返回第一次出現該值的位置 *

* @param array 已排序的陣列

* @param start 開始位置

* @param end 結束位置

* @param findvalue 需要找的值

* @return 值在陣列中的位置,從0開始。找不到返回-1

*/public static int searchrecursive(int array, int start, int end,

int findvalue)

if (start <= end) else if (findvalue < middlevalue) else

} else

}}

Java中常用工具類的練習

public class testcheckusername 長度大於6,if username.length 6 不能有數字 for int i 0 i 0 system.out.println 使用者名稱符合要求 public class teststringconvert catch pars...

java常用工具類作業

public class demotest 輸出結果 請輸入乙個日期 4月9日2019年 2019年4月9日2.給出乙個隨機字串,判斷有多少字母?多少數字?思路 先把string字串轉換成字元陣列,在用迴圈出來的字元跟ascii比較,大寫字母的ascii值在65 90之間,小寫字母在97 122之間...

Java常用工具

自動生成18位id verifycode.setid uniquenumberutils.get18uniquenumber dateutils.gettimestamp string轉為date型別 dateformat sdf new dateformat yyyy mm dd date sta...