黑马程序员技术交流社区

标题: 成都校区 [打印本页]

作者: Lison.cd    时间: 2018-11-22 12:45
标题: 成都校区
import java.util.Scanner;
//这个代码有点意思

public class AA {
    public static void main(String[] args) {
        OK:
        while (true) {

            System.out.println("输入一串大写字母");
            Scanner sc = new Scanner(System.in);
            String str = sc.next();
            char[] chars = str.toCharArray();
            int l = chars.length;
            long sum = 0;
            for (int i = 0; i < chars.length; i++, l--) {
                if (chars[i]<65 || chars[i]>90){
                    System.out.println("输入的不是纯大写字母");
                    System.out.println("================================");
                    continue OK;
                }
                int x = 1;
                for (int j = 0; j < l-1; j++) {
                    x = 26 * x;
                }
                long count = (chars[i] - 64) * x;
                sum += count;

            }
            System.out.println(sum);
            System.out.println("================================");
        }
    }
}




欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2