public class Test2 {
public Test2(){
//1
String s="7s中文df*&^$*sh8s7dg4好9ds2";
String news=deleteNotCharacter(s);
System.out.println(s);
System.out.println(news);
//2
int[][] array=new int[][]{{3,2,3},{2,3,4},{4,5,6}};
int length = array.length;
for (int i = 0; i < length; i++) {
for (int j = 0; j < length; j++) {
System.out.print(array[i][j]+" ");
}
System.out.println();
}
int[] n=getDiagonal(array);
System.out.println("主对角线:"+n[0]+" 副对角线:"+n[1]);
}
private String deleteNotCharacter(String s) {
char[] cs=s.toCharArray();
StringBuilder sb=new StringBuilder();
for(char c:cs){
if((c>='a'&&c<='z')||(c>='A'&&c<='Z'))
sb.append(c);
}
return sb.toString();
}
private int[] getDiagonal(int[][] array) {
int[] result=new int[]{0,0};
int length=array.length;
for(int i=0;i result[0]+=array[i][i];
result[1]+=array[i][length-i-1];
}
return result;
}
public static void main(String[] args) {
new Test2();
}
}