A title:
Problem 1: to write an application, a number of the same characters in the string of biometric input, output and the statistical results.
Problem 2: programming, a string input, determining whether the letter string composed of a palindromic sequence (palindromic sequence: a string read from the front and back are the same read from back to front). Such as: ab <c> c ba?
Second code:
wenbowindf.ScamnnerSameString Package; public class Demo {// Xiexiao Fei reference code, the specific code is modestly I learning process, and has been comprehensively public static void main (String [] args) { Palindrome.Palindrome ( "ABCBA"); CompareStrings. getNum ( "teacher, please ask my bedroom brother - Zhang Jiuchuan"); } }
package wenbowindf.ScamnnerSameString; import java.util.Iterator; import java.util.LinkedList; public class CompareStrings { public static void getNum(String str) { LinkedList<Character> link = new LinkedList<Character>(); int []num = new int[100] ; int count = 0; int index = 0; int index1 = 0; for(int i = 0; i < str.length(); i++) { count=0; for(int j = 0; j < str.length(); j++) { if (str.charAt(i)==str.charAt(j)){ count++; } } if(!(link.contains(str.charAt(i)))) { link.add(str.charAt(i)); num[index++]=count; } } Iterator<Character> it = link.iterator(); while(it.hasNext()) { System.out.println(it.next()+":"+num[index1++]); index++; } } }
package wenbowindf.ScamnnerSameString; public class Palindrome { public static void Palindrome(String str) { char []ch = str.toCharArray(); boolean flag = true; int len = ch.length; for(int i =0;i<len;i++) { if(ch[i]!=ch[len-i-1]) { flag = false; } } if(flag) { System.out.println(str+"是回文"); }else { System.out.println(str+"不是回文"); } } }
Three operating results: