package com.coding.syudy05;
/**
* 输入一个QQ邮箱或者网易邮箱,判断其格式是否正确
* 要求:长度不能超过15,@前面不能用字母
* 正确格式2156636@qq.com
*/
import java.util.Scanner;
public class Demo08 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("请输入你的邮箱:");
String s1 = scanner.nextLine();
char[] c = s1.toCharArray();
boolean flag=true;
if (c.length<15) {
for (int i = 0; i < c.length; i++) {
if (c[0] == '0') {
System.out.println("输入错误");
break;
}
if (c[i] == '@') {
for (int j = 0; j < i; j++) {
if (!Character.isDigit(c[j])) {
System.out.println("格式错误!!");
flag=false;
break;
}
}
if (flag) {
String s2 = s1.substring(i + 1);
if (s2.equals("qq.com") || s2.equals("163.com")) {
System.out.println("输入正确");
}
}
}
}
}
else {
System.out.println("长度超出范围");
}
}
}