算法面试题(三)

将“I am a student.”转换为“student. a am I”


 1package test;
 2import java.util.Arrays;    
 3public class Test7 {    
 4    public static void main(String[] args) {    
 5        String str ="I am a student.";
 6        String[] sArr = str.split(" ");
 7        //外层控制轮数
 8        for (int i = 0; i 

String str1 = "abcwerthelloyuiodef";String str2 = "cvhellobnm";求两个字符串的最大相同子串



1package test;   
 2public class Test8 {    
 3    public static void main(String[] args) {            
 4        String str1 = "abcwerthelloyuiodef";
 5        String str2 = "cvhellobnm";
 6        sop(getMaxSubString(str2,str1));
 7        str2.toCharArray(); 
 8    }
 9
10    public static String getMaxSubString(String s1,String s2)
11    {
12        //求出长串、短串
13        String max = "",min = "";
14        max = (s1.length()>s2.length())?s1: s2;
15        min = (max==s1)?s2: s1;     
16//      sop("max="+max+"...min="+min);
17        for(int x=0; x

单例设计模式

饿汉式:


 1package test;
 2public class Test9 {    
 3    //私有化构造方法
 4    private Test9(){};
 5    //私有化静态成员变量
 6    private static Test9 test = new Test9();
 7    //公有的静态方法
 8    public static Test9 getTest9(){
 9        return test;
10    }
11
12    public static void main(String[] args) {
13        System.out.println(Test9.getTest9()==Test9.getTest9());
14    }
15}

懒汉式:



 1package test;
 2    public class Test9 {    
 3        //私有化构造方法
 4        private Test9(){};
 5        //私有化静态成员变量
 6        private static Test9 test = null;
 7        //公有的静态方法
 8        public static Test9 getTest9(){
 9            if(test == null){
10                test = new Test9();
11            }
12            return test;
13        }
14
15        public static void main(String[] args) {
16            System.out.println(Test9.getTest9()==Test9.getTest9());
17        }
18    }

原文发布时间为:2018-09-16 本文作者: IT技术之道 本文来自云栖社区合作伙伴“IT技术之道”,了解相关信息可以关注“ IT技术之道 ”。


你可能感兴趣的:(算法面试题(三))