gpt4 book ai didi

java - j掌握。需要帮助。不知道如何编码

转载 作者:行者123 更新时间:2023-12-02 05:22:41 25 4
gpt4 key购买 nike

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

最佳答案

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

关于java - j掌握。需要帮助。不知道如何编码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26372126/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com