answer.
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
jeyben [28]
2 years ago
5

Write a method, isEmailAddress, that is passed a String argument. It returns true or false depending on whether the argument has

the form of an email address. In this exercise, assume that an email address has one and only one "@" sign and no spaces, tabs or newline characters.
Computers and Technology
1 answer:
Pavel [41]2 years ago
8 0

Answer:

//Method declaration taking a parameter called myString of type String

public static boolean isEmailAddress (String myString){

//checking the @ character exists in string

if (myString.indexOf("@") != -1) {

  //checking if only one instance of @ exist in the string

   if (myString.indexOf("@") == myString.lastIndexOf("@")) {

   //checking if there's no space character

  if (myString.indexOf(" ") == -1) {

    //checking if there's no newline character in the string

    if (myString.indexOf("\n") == -1) {

      // checking if there's no tab character in the string

      if (myString.indexOf("\t") == -1) {

          return true;

      }

    }

  }

}

}

 return false;

}

Explanation:

The method takes in a string which is supposed to be an email address and checks if it is a valid email, it returns true if it is a valid email and returns false if not. the method checks the following conditions along the way.

->If "@" exists

->If there's only one "@" in the string

->If space character does not exists

->If newline character does not exists

->If tab character does not exist

it returns true if all the conditions are true.

You might be interested in
A network administrator has received the IPv6 prefix 2001:DB8::/48 for subnetting. Assuming the administrator does not subnet in
AveGali [126]

Answer:

subnets=65536

Explanation:

As we know that,

-->interface ID portion of address starts from 64

--> we have 48 network prefix

so

available bits for subnet are = 64-48=  16

so with 16 bit address we can create subnet = 2^16 = 65535

6 0
2 years ago
You want to register the domain name ABCcompany.org, but the registration service is not allowing you to do that. What's the mos
Andreyy89

Options :

The domain name is registered to someone else.

Domain names must end in ".com".

You are not the legal owner of ABC Company.

Domain names must be all in lowercase.

Answer:

The domain name is registered to someone else.

Explanation: In the scenario above, ABCcompany.org represents the domain name of a particular person or establishment which provides access to the website of the owner. The domain name given to an individual or website must be distinct, that is no two different organizations or persons can use exactly the same domain name. Domain names can end with :. com, org, ng and various other and they aren't case sensitive. Therefore, the inability to register the domain name abive will likely stem from the fact that the domain name has is already registered to someone else.

6 0
2 years ago
You live "out in the middle of nowhere" and feel there is no need to protect your internet connection because there is no one th
Anvisha [2.4K]

Potential uploaded viruses, personal information being lost, blackmail, identity theft.

7 0
2 years ago
2) Complete the get_num_of_characters() function, which returns the number of characters in the user's string. We encourage you
Lilit [14]

Explanation:

Number of characters: 46

String with no whitespace: Theonlythingwehavetofearisfearitself.

########################################################

def get_num_of_characters(inputStr):

   count = 0

   for i in range(0,len(inputStr)):

       count = count + 1

   #count = len(inputStr)

   return count

def output_without_whitespace(inputStr):

   #statement = statement.strip()

   statement2 = ' '

   for i in range(0,len(inputStr)):

        if(inputStr[i] == ' '):

           statement2 = statement2

       else:

           statement2 = statement2 + inputStr[i]

       

   inputStr = inputStr.replace(" ", "")

   return statement2

inputStr = input('Enter a sentence or phrase: ')

print()

print('You entered:', inputStr)

num = get_num_of_characters(inputStr)

print()

print('Number of characters:', num)

print('String with no whitespace:',output_without_whitespace(inputStr))

#if __name__ == '__main__':

   # Think I'm supposed to use this if statement

########################################################

'''ERROR MESSAGE WHEN RUNNING TEST

Unit test

0/1

Tests that get_num_of_characters() returns 46 for "The only thing we have to fear is fear itself."

Your output

Enter a sentence or phrase: Traceback (most recent call last):

 File "zyLabsUnitTestRunner.py", line 4, in <module>

   from zyLabsUnitTest import test_passed

 File "/home/runner/local/unit_test_student_code/zyLabsUnitTest.py", line 1, in <module>

   from main import get_num_of_characters

 File "/home/runner/local/unit_test_student_code/main.py", line 19, in <module>

   inputStr = input('Enter a sentence or phrase: ')

EOFError: EOF when reading a line'''

6 0
2 years ago
a.Write a Python function sum_1k(M) that returns the sum푠푠= ∑1푘푘푀푀푘푘=1b.Compute s for M = 3 by hand and write
stealth61 [152]

Answer:

def sum_1k(M):

   s = 0

   for k in range(1, M+1):

       s = s + 1.0/k

   return s

def test_sum_1k():

   expected_value = 1.0+1.0/2+1.0/3

   computed_value = sum_1k(3)

   if expected_value == computed_value:

       print("Test is successful")

   else:

       print("Test is NOT successful")

test_sum_1k()

Explanation:

It seems the hidden part is a summation (sigma) notation that goes from 1 to M with 1/k.

- Inside the <em>sum_1k(M)</em>, iterate from 1 to M and calculate-return the sum of the expression.

- Inside the <em>test_sum_1k(),</em> calculate the <em>expected_value,</em> refers to the value that is calculated by hand and <em>computed_value,</em> refers to the value that is the result of the <em>sum_1k(3). </em>Then, compare the values and print the appropriate message

- Call the <em>test_sum_1k()</em> to see the result

8 0
2 years ago
Other questions:
  • Gloria needs to show in spreadsheet form the number of students in her class who speak different languages. Which type of graph
    7·1 answer
  • In what year were graphical user interfaces (GUIs) pioneered? 1969 1974 1991 2001
    12·2 answers
  • An electronics store purchased a CD player at a wholesale price of $60 and then sold it at a 40 percent discount off the origina
    13·1 answer
  • Assume there is a class AirConditioner that supports the following behaviors: turning the air conditioner on and off. The follow
    7·1 answer
  • Remember that it is desirable for good block ciphers that a change in one input bit affects many output bits, a property that is
    9·1 answer
  • Consider the following two code segments, which are both intended to determine the longest of the three strings "pea", "pear", a
    7·1 answer
  • If a class has member variables that are pointers, you must ensure that you implement ____.
    6·1 answer
  • A semaphore puts a thread to sleep:
    12·1 answer
  • In this exercise you will debug the code which has been provided in the starter file. The code is intended to take two strings,
    7·1 answer
  • Doug grew up on a large farm in southwest Wisconsin. As a college graduation gift, Doug’s father gave him several hundred acres
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!