赞
踩
目录
finally 语句块一定会被执行,且在 catch 语句块返回前被执行。
先执行 test.add,finally 一定会被执行到,所以打印 finally,再返回43,最后打印和是43
a 是成员变量,存在堆区, b 和 c 都是局部变量,存在栈上
abstract 和 final 不能同时出现。因为 final 表示不可变,而被 abstract 修饰的方法则需要被重写、实现。
abstract 一般修饰类和方法,不能修饰变量。
当代码执行到 100/0,就会抛算术异常,就会去执行被捕捉到的 catch 块,打印 1,抛异常,然后再去执行 finally。
计算时,如果不初始化并赋值变量,后面再用时就会进行整型提升,因为 b4 被 final 修饰所以不会进行整型提升,而 b1 和 b2 进行整型提升,但是 b3 却还是 byte,所以类型不匹配(大转小)。
数组越界了,最大下标等于数组元素个数 - 1。
这个很简单,直接根据题目说的写,将 大写字母,小写字母,数字,符号各定义一个计数器,然后遍历字符串,遇到对应的就计数器++,然后根据规则判断即可。
代码实现:
- import java.util.*;
-
- // 注意类名必须为 Main, 不要有任何 package xxx 信息
- public class Main {
- public static void main(String[] args) {
- Scanner in = new Scanner(System.in);
- // 注意 hasNext 和 hasNextLine 的区别
- while (in.hasNextLine()) { // 注意 while 处理多个 case
- String str = in.nextLine();
- printScore(str);
- }
- }
-
- public static void printScore(String str) {
- int score = 0;
- // 密码长度:
- if (str.length() <= 4) {
- score += 5;
- } else if (str.length() >= 8) {
- score += 25;
- } else {
- score += 10;
- }
-
- // 大写字母计数器
- int A = 0;
- // 小写字母计数器
- int a = 0;
- // 数字计数器
- int n = 0;
- // 符号计数器
- int $ = 0;
- for (char x : str.toCharArray()) {
- if (x >= '0' && x <= '9') {
- n++;
- } else if (x >= 'a' && x <= 'z') {
- a++;
- } else if (x >= 'A' && x <= 'Z') {
- A++;
- } else {
- $++;
- }
- }
- // 字母:
- if (A > 0 && a > 0) {
- score += 20;
- } else if (A > 0) {
- score += 10;
- } else if (a > 0) {
- score += 10;
- }
-
- // 数字:
- if (n > 1) {
- score += 20;
- } else if (n == 1) {
- score += 10;
- }
-
- // 符号:
- if ($ > 1) {
- score += 25;
- } else if ($ == 1) {
- score += 10;
- }
-
- // 奖励:
- if (A > 0 && a > 0 && n > 0 && $ > 0) {
- score += 5;
- } else if (A > 0 && n > 0 && $ > 0) {
- score += 3;
- } else if ( a > 0 && n > 0 && $ > 0) {
- score += 3;
- } else if (a > 0 && n > 0) {
- score += 2;
- } else if (A > 0 && n > 0) {
- score += 2;
- }
-
-
- // 最后的评分标准:
- if (score >= 90) {
- System.out.println("VERY_SECURE");
- } else if (score >= 80) {
- System.out.println("SECURE");
- } else if (score >= 70) {
- System.out.println("VERY_STRONG");
- } else if (score >= 60) {
- System.out.println("STRONG");
- } else if (score >= 50) {
- System.out.println("AVERAGE");
- } else if (score >= 25) {
- System.out.println("WEAK");
- } else if (score >= 0) {
- System.out.println("VERY_WEAK");
- }
-
- }
- }

Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。