随笔分类 - 编程题
摘要:/** * 斐波那契数列 */public static int fib(int n){ if(n==1) return 0; if(n==2) return 1; return fib(n-1) + fib(n-2);}
阅读全文
摘要:/** * 单例模式:懒汉式 */class Singleton{ private static volatile Singleton singleton = null; private Singleton(){ } public static Singleton getInstance(){ if
阅读全文
摘要:/** * 冒泡排序 * @param arr */public static void bubbleSort(int [] arr){ for(int i= 0;i < arr.length -1;i++){ for (int j=0;j < arr.length-1-i;j++){ if(arr
阅读全文
摘要:public class ManyThreads2 { private int j = 0; public synchronized void inc() { j++; System.out.println(Thread.currentThread().getName() + "inc" + j);
阅读全文
摘要:public static void test(String str){Map<String,Integer> map = new HashMap<>();for(int i = 0 ;i < str.length();i++){String s = str.charAt(i) + "";if(ma
阅读全文
摘要:public String reverse(String str){ if(str == null || str.length() <= 1){ return str; } return reverse(str.subString(1)) + str.charAt(0); }
阅读全文

浙公网安备 33010602011771号