1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
iogann1982 [59]
3 years ago
15

For this programming assignment, you have to write a Java program that tests whether a given input string represents a Valid E-m

ail address. If the input is not a valid e-mail address, it should print a message saying "Invalid Address". If the input is a valid e-mail address, it should print out the User name and the Domain name on separate lines. For purposes of this assignment and to keep the logic simple, a valid E-mail address will be of the form
Computers and Technology
1 answer:
Step2247 [10]3 years ago
8 0

Answer:

To check if the email address is correct it should have only one "@" symbol, we have to split the input string by this symbol. The code in java to achieve this is the following:

class Main {

 public static void main(String[] args) {

   String email = "[email protected]";

   String[] email_split = email.split("@");

   long count_a = email.chars().filter(ch -> ch == '@').count();

   if(count_a == 1){

     System.out.println("User name:   "+email_split[0]);

     System.out.println("Domain name: "+email_split[1]);

   }else{

     System.out.println("There is no valid email address.");

   }

 }

}

Explanation:

The explanation of the code is given below:

class Main {

 public static void main(String[] args) {

   String email = "[email protected]"; //input string to evaluate if is valid email

   long count_a = email.chars().filter(ch -> ch == '@').count(); //Count how many times the symbol @ appears

   if(count_a == 1){ //A valid email only contains one at

     String[] email_split = email.split("@"); //separate the values using the at in an array

     System.out.println("User name:   "+email_split[0]); //the first element is the username

     System.out.println("Domain name: "+email_split[1]); //the second element is the domain name

   }else{

     System.out.println("There is no valid email address."); //If there isn´t an at or are more than one then display a message saying the email is not valid

   }

 }

}

You might be interested in
Attetion developers i have a question can u devlop a website
Eva8 [605]
Yes, you can, with certain apps or with websites. Try Mozilla Web Maker.
3 0
3 years ago
Read 2 more answers
WILL GIVE BRAINLIEST IF DONE CORRECT
Juliette [100K]

Answer:

import sys

#account balance

account_balance = float(500.25)

##prints current account balance

def printbalance():

  print('Your current balance: %2g'% account_balance)

#for deposits

def deposit():

 #user inputs amount to deposit

 deposit_amount = float(input())

 #sum of current balance plus deposit

 balance = account_balance + deposit_amount

 # prints customer deposit amount and balance afterwards

 print('Deposit was $%.2f, current balance is $%2g' %(deposit_amount,

balance))

#for withdrawals

def withdraw():

 #user inputs amount to withdraw

 withdraw_amount = float(input())

 #message to display if user attempts to withdraw more than they have

 if(withdraw_amount > account_balance):

   print('$%.2f is greater than your account balance of $%.2f\n' %

(withdraw_amount, account_balance))

 else:

   #current balance minus withdrawal amount

   balance = account_balance - withdraw_amount

   # prints customer withdrawal amount and balance afterwards

   print('Withdrawal amount was $%.2f, current balance is $%.2f' %

(withdraw_amount, balance))

#system prompt asking the user what they would like to do

userchoice = input ('What would you like to do? D for Deposit, W for

Withdraw, B for Balance\n')

if (userchoice == 'D'): #deposit

 print('How much would you like to deposit today?')

 deposit()

elif userchoice == 'W': #withdraw

 print ('How much would you like to withdraw today?')

elif userchoice == 'B': #balance

 printbalance()

else:

 print('Thank you for banking with us.')

 sys.exit()

6 0
3 years ago
Read 2 more answers
Which actions changed the look of the following word
Tju [1.3M]
What’s the word? There is no word here?
8 0
3 years ago
Solve the equation w - 2 = -3<br><img src="https://tex.z-dn.net/?f=w%20%3D%20%20%20-%20%20%5Cfrac%7B3%7D%7B2%7D%20" id="TexFormu
Andreyy89
Heres my answer w= -1
4 0
3 years ago
Answer to get brainiest. I NEED HELP PLEASE!! I am supposed to type a program on base conversion. Starts from base of 10 (decima
Virty [35]

Here's a solution that works except for the leading zeros. Unclear (to me) why they need to be there and what's the logic?


  public static void main(String[] args)  

  {    

       int number, base;

       Scanner Cin = new Scanner(System.in);  

       System.out.print("Enter a decimal number between 1 and 100,000: ");

       number = Cin.nextInt();

       System.out.print("Enter a base from 2-16: ");

       base = Cin.nextInt();          

       System.out.format("The number %d in base %d is %s.", number, base, Integer.toString(number, base).toUpperCase());

  }

6 0
4 years ago
Other questions:
  • HELLLLLP ill make you brainiest and ill give u a lot of points if you HELP ME Directions Part One.
    12·2 answers
  • Search engines enable you to
    9·2 answers
  • Which of the following are recommended techniques for protecting computer files and data? Check all of the boxes that apply.
    15·2 answers
  • The DNS server at your headquarters holds a standard primary zone for the abc domain. A branch office connected by a slow WAN li
    14·1 answer
  • Which of the following is an example of batch processing?
    14·1 answer
  • According to Ohm's Law current equals what?
    7·2 answers
  • ____ is a consistent relational database state in which every foreign key value also exists as a primary key value.​ a. ​ Refere
    11·1 answer
  • In spreadsheets, a cell reference is also referred to as which of the following? A. active cell B. axis C. cell address D. entry
    9·1 answer
  • I need help 50 points and brainiest if you answer
    10·2 answers
  • Can anyone talk to me?
    9·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!