学生使用作业提交系统提交java作业,输入java源文件名,并输入自己的邮箱,提交前进行系统检查:是否是合法的java文件名:邮箱是否适合发邮箱。设计实现提交前检查部分功能。
/*HandInTask.java*/
import java.util.*;
public class HandInTask{
public static void main(String[] args){
boolean fileNameCorrect=false;
boolean emailNameCorrect=false;
System.out.println("————学生作业提交系统————");
Scanner input=new Scanner(System.in);
System.out.println("请输入java源文件名:");
String fileName=input.next();
System.out.println("请输入你的邮箱:");
String emailName=input.next();
//检查java源文件名
int index=fileName.lastIndexOf(".");
if(index!=-1&&index!=0&&fileName.substring(index+1,fileName.length()).equals("java")){
fileNameCorrect=true; //文件名正确
} else {
System.out.println("文件名无效。");
}
//检查邮箱格式
if(emailName.indexOf('@')!=-1&&emailName.indexOf('.')>emailName.indexOf('@')){
emailNameCorrect=true;
} else {
System.out.println("E-mail 无效");
}
if(fileNameCorrect&&emailNameCorrect){
System.out.println("作业提交成功!");
} else
System.out.println("作业提交失败!");
}
}
输出结果:
![](https://img-blog.csdn.net/20131022172453234)