vaineb
vaineb

Reputation: 1

jgrasp. need assistance. cannot figure out how to code this

An email address contains the @ character. Write a program that takes a word from the keyboard and outputs whether it is an email address based on the presence of the @ character. Do not worry about what else is in the word.

Upvotes: 0

Views: 549

Answers (3)

Snare_Dragon
Snare_Dragon

Reputation: 59

I don't know why y'all making this code so complicated?!

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

Upvotes: 0

Cute_kittens
Cute_kittens

Reputation: 33

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

Upvotes: 2

Dennis
Dennis

Reputation: 1

 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


  }
}

Upvotes: 0

Related Questions