0

电子邮件地址包含@ 字符。编写一个程序,从键盘输入一个单词,并根据 @ 字符的存在输出它是否是电子邮件地址。不要担心这个词还有什么。

4

3 回答 3

2
import java.util.Scanner;
  public class EmailAddress {
    public static void main(String[] args) { 
      Scanner input = new Scanner(System.in);
      System.out.print(" Enter a word: " );
      String word = input.nextLine();
      int count = 0;
      for(int i = 0; i < word.length(); i++) {
        if(word.charAt(i) == '@')
          count++;
      }
      if(count > 0) 
        System.out.println("Its an E-mail ");
      else
        System.out.println("Its not an E-mail ");
   }
 }     
于 2016-02-11T06:59:28.810 回答
0

我不知道你们为什么要把这段代码弄得这么复杂?!

import java.util.Scanner;
import java.util.*; //I Always import this as a good habit
public class EmailAddress
{
    public static void main(String[] args)
    { 
        Scanner input = new Scanner(System.in);
        System.out.print(" Enter a word: " );
        String word = input.nextLine();
        if(word.contains('@'))
        {
            System.out.println("It's an Email");
        }
        else
        {
            System.out.println("It's not an Email");
        }
    }
}
于 2018-11-16T20:20:30.010 回答
0
 import  java.util.Scanner;                                //Imports the scanner function

public class TestingCode {                                 //standard java input
 public static void main(String args[]) {                  //standard java input
  Scanner scan = new Scanner (System.in) ;                 //asks the user to input the email they would like to find the domain for
    System.out.print ( "What is the email? : " );
    String email = scan.next();                            //scans for the next string
    int index = email.indexOf('@') ;                       //finds the index at which the @ is located at and stores it as index
    String domain = email.substring (index , email.length() ); //uses the substring function to cut out everything before the @ symbol and stores that snippet as variable domain .
    System.out.print("The email domain is " + domain );     //displays variable domain


  }
}
于 2016-02-11T06:39:45.317 回答