题目:

     利用String类或StringBuffer类的方法,对输入的Email地址进行有效性验证。提示:
         (1)Email地址中应包含“@”和“.”符号;
         (2)“@”符号应该在“.”符号之前;
         (3)“@”符号不应该在Email地址的起始位置;

源代码:

package org.java.application;


import java.util.Scanner;


//邮箱类


public class Email {


public static void main(String[] args) {
String email=null;
{
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("邮箱地址无效。");
}
}
}
}

课后作业之邮箱类

相关文章:

  • 2021-12-16
  • 2022-12-23
  • 2021-12-10
  • 2021-09-16
猜你喜欢
  • 2021-06-07
  • 2021-12-01
  • 2021-05-29
  • 2022-02-02
  • 2021-12-02
  • 2021-07-12
  • 2021-12-20
相关资源
相似解决方案