JAVA作业2

来源:互联网 发布:帝国的终结 知乎 编辑:程序博客网 时间:2024/06/08 06:38
1、利用String类或StringBuffer类的方法,对输入的Email地址进行有效性验证。提示:
         1)Email地址中应包含“@”和“.”符号;
         2)“@”符号应该在“.”符号之前;
         3)“@”符号不应该在Email地址的起始位置
2、一个班级的学生成绩存在长度为10的数组中,计算不及格的学生数目 

1:代码1

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



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]);
}
}
}
}


运行测试:


 

原创粉丝点击