Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.util.Scanner;
- /*
- Amon Guinan
- Friday, January 25.
- Program detects whether emails have a single "@" or not.
- */
- public class exercises {
- public static void main(String [] args)
- {
- String email;
- System.out.println("Enter a valid email address.");
- Scanner input = new Scanner(System.in);
- email = input.nextLine();
- if(email.indexOf("@") == -1)
- {
- System.out.print("Invalid email address.");
- System.exit(255);
- }
- email = email.replaceFirst("@","_");
- if(email.indexOf("@") != -1){
- System.out.print("Invalid email address.");
- }
- else
- {
- System.out.print("Valid email address.");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment