您的位置:首页 > 编程语言 > Java开发

java语言程序设计第十版(Introduce to java) 课后习题 chapter6-18

2016-03-21 19:51 519 查看
java语言程序设计第十版(Introduce to java) 课后习题 chapter6-18

自己纯手工,欢迎讨论package chapter6;

import java.util.Scanner;

public class T18 {

public static void main(String[] args) {

Scanner in = new Scanner(System.in);

String s = null;

do {
System.out.println("Enter the password more than 8 letters:");
s = in.nextLine();
} while (s.length() < 8);

char[] c = s.toCharArray();
int no = 0;
int letter = 0;
int num = 0;
for (char e : c) {
if (!Character.isLetterOrDigit(e))
no++;
// if(Character.isLetter(e))
// letter++;
if (Character.isDigit(e))
num++;
}
if (no > 0)
System.out.println("有非字母和数字的字符");
if (num < 2)
System.out.println("数字不够2个");
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息