您的位置:首页 > Web前端

1、利用String类或StringBuffer类的方法,对输入的Email地址进行有效性验证。提示:          1)Email地址中应包含“@”和“.”符号;          2)“@”符

2017-12-28 12:58 549 查看
import java.util.Scanner;  
public class Youxiang {  
    public static void main(String[] args) {  
        String email=null;  
        int a=0;  
        while(a++<=3){  
            Scanner input=new Scanner(System.in );  
            System.out.print("请输入email地址 :");  
            email=input.next();  
            if (email.indexOf('@') != -1  
                    && email.indexOf('.') > email.indexOf('@')) {  
                System.out.println("邮箱地址合法!");  
            } else {  
                System.out.println("邮箱地址无效。");  
                break;  
            }  
            if (a == 3) {  
                System.out.println("次数超限!请3小时以后再试;");  
                break;  
            }  
        }  
    }  
}  
import java.util.Scanner;
public class Youxiang {
public static void main(String[] args) {
String email=null;
int a=0;
while(a++<=3){
Scanner input=new Scanner(System.in );
System.out.print("请输入email地址 :");
email=input.next();
if (email.indexOf('@') != -1
&& email.indexOf('.') > email.indexOf('@')) {
System.out.println("邮箱地址合法!");
} else {
System.out.println("邮箱地址无效。");
break;
}
if (a == 3) {
System.out.println("次数超限!请3小时以后再试;");
break;
}
}
}
}


运行测试:



代码:2

[java]
view plain
copy

print?

public class Score {  
    public static void main(String[] args) {  
        System.out.println("计算本组成员的考试总分数");  
        int score[] = { 94, 89, 79, 56, 81, 73, 58, 63, 49, 55 };  
        for (int i = 0; i < 10; i++) {  
            System.out.print(score[i]);  
            System.out.print("  ");  
        }  
        for(int a = 0; a <10 ; a++){  
            if(score[a] <60){  
                System.out.println("不及格的分数有:"+score[a]);  
            }  
        }  
    }  
}  

public class Score {
public static void main(String[] args) {
System.out.println("计算本组成员的考试总分数");
int score[] = { 94, 89, 79, 56, 81, 73, 58, 63, 49, 55 };
for (int i = 0; i < 10; i++) {
System.out.print(score[i]);
System.out.print("  ");
}
for(int a = 0; a <10 ; a++){
if(score[a] <60){
System.out.println("不及格的分数有:"+score[a]);
}
}
}
}


运行测试:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  java
相关文章推荐