选择题
public class Test01 {
public static void main(String[] args) {
try{
int i = 100 / 0;
System.out.print(i);
}catch(Exception e){
System.out.print(1);
throw new RuntimeException();
}finally{
System.out.print(2);
}
System.out.print(3);
}
}
编程题
题目1
import java.util.*;
public class Board {
public static boolean checkWon(int[][] board) {
int n = board.length;//n行 3
int m = board[0].length;//m列 3
int f1 = 0;
int f2 = 0;
//先检查行
for(int i=0;i<n;i++) {
f1 = 0;
f2 = 0;
for(int j=0;j<m;j++) {
if(board[i][j] == 1)
f1++;
if(board[i][j] == -1)
f2++;
}
if(f1 == m) {
return true;
}
if(f2 == m) {
return false;
}
}
f1 = 0;
f2 = 0;
//再检查列
for(int i=0;i<m;i++) {
f1 = 0;
f2 = 0;
for(int j=0;j<n;j++) {
if(board[j][i] == 1)
f1++;
if(board[j][i] == -1)
f2++;
}
if(f1 == n) {
return true;
}
if(f2 == n) {
return false;
}
}
f1 = 0;
f2 = 0;
//检查斜列
for(int i=0;i<n;i++) {
if(board[i][i] == 1) {
f1++;
}
if(board[i][i] == -1)
f2++;
}
if(f1 == n) {
return true;
}
if(f2 == n) {
return false;
}
f1 = 0;
f2 = 0;
for(int i=0;i<n;i++) {
for(int j=0;j<m;j++) {
if(i == (n-j-1)) {
if(board[i][j] == 1)
f1++;
if(board[i][j] == -1)
f2++;
}
}
}
if(f1 == n) {
return true;
}
if(f2 == n) {
return false;
}
return false;
}
}
题目2
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String s = sc.next();
sc.nextLine();
int sum = 0;
//1
if (s.length() <= 4) {
sum += 5;
} else if (s.length() >= 5 && s.length() <= 7) {
sum += 10;
} else if (s.length() >= 8) {
sum += 25;
}
//2
boolean f1 = false;
boolean f2 = false;
int cum1 = 0;
int cum2 = 0;
for (int i = 0; i < s.length(); i++) {
if (s.charAt(i) >= 'a' && s.charAt(i) <= 'z') {
f1 = true;
cum1++;
}
if (s.charAt(i) >= 'A' && s.charAt(i) <= 'Z') {
f2 = true;
cum2++;
}
}
if (f1 && f2) {
sum += 20;
} else if (f1 || f2) {
sum += 10;
} else {
sum += 0;
}
//3
int num = 0;
for (int i = 0; i < s.length(); i++) {
if (s.charAt(i) >= '0' && s.charAt(i) <= '9') {
num++;
}
}
if (num == 0) {
sum += 0;
} else if (num == 1) {
sum += 10;
} else if (num > 1) {
sum += 20;
}
//4
// !"#$%&'()*+,-./ (ASCII码:0x21~0x2F)33 - 47
// :;<=>?@ (ASCII码:0x3A~0x40)58 - 64
// [\]^_` (ASCII码:0x5B~0x60)91 - 96
// {|}~ (ASCII码:0x7B~0x7E)123 - 126
int team = 0;
for (int i = 0; i < s.length(); i++) {
if (s.charAt(i) >= 33 && s.charAt(i) <= 47) {
team++;
} else if (s.charAt(i) >= 58 && s.charAt(i) <= 64) {
team++;
} else if (s.charAt(i) >= 91 && s.charAt(i) <= 96) {
team++;
} else if (s.charAt(i) >= 123 && s.charAt(i) <= 126) {
team++;
}
}
if (team == 0) {
sum += 0;
} else if (team == 1) {
sum += 10;
} else if (team > 1) {
sum += 25;
}
//5
if (cum1 != 0 && cum2 != 0 && num != 0 && team != 0) {
sum += 5;
} else if ((cum1 != 0 || cum2 != 0) && num != 0 && team != 0) {
sum += 3;
} else if ((cum1 != 0 || cum2 != 0) && num != 0) {
sum += 2;
}
//
if (sum >= 90) {
System.out.println("VERY_SECURE");
} else if (sum >= 80) {
System.out.println("SECURE");
} else if (sum >= 70) {
System.out.println("VERY_STRONG");
} else if (sum >= 60) {
System.out.println("STRONG");
} else if (sum >= 50) {
System.out.println("AVERAGE");
} else if (sum >= 25) {
System.out.println("WEAK");
} else if (sum >= 0) {
System.out.println("VERY_WEAK");
}
sc.close();
}
}