Java的Anagram程序
#java #面试 #list #strings

用于解释观看视频

代码::

import java.util.*;
import java.lang.*;
class Demo{
    public static void main(String[] args){
        String s1 = "keepp";
        String s2 = "peek";
        char[] ch1 = s1.toCharArray();
        char[] ch2 = s2.toCharArray();
        Arrays.sort(ch1);
        Arrays.sort(ch2);
        String ss1 = new String(ch1);
        String ss2 = new String(ch2);
        if(ss1.equals(ss2)){
            System.out.println("anagram");
        }else{
            System.out.println("not anagram");
        }
    }
}