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
VARVARA [1.3K]
3 years ago
5

Given two integers low and high representing a range, return the sum of the integers in that range. For example, if low is 12 an

d high is 18, the returned values should be the sum of 12, 13, 14, 15, 16, 17, and 18, which is 105. If low is greater than high, return 0.
Examples:

sumRange(12, 18) -> 105

sumRange(1, 5) -> 15

sumRange(1, 100) -> 5050
Computers and Technology
1 answer:
Vaselesa [24]3 years ago
8 0

       System.out.println(sumRange(12, 18)); // prints 105

       System.out.println(sumRange(18, 12)); // prints 0

       System.out.println(sumRange(18, 18)); // prints 18

   }

   public static int sumRange(int low, int high)

   {

       int sum = 0;

       for (int val = low; val <= high; val++){

           sum += val;

       }

       return sum;

   }

}

You might be interested in
Is this statement true or false?
____ [38]
This answer could be either, but personally false. Humor drives attention into your work (if the humor isn’t about it then yes it would drive it far off) but it makes people focus and listen to your presentation so they would answer your jokes. Hope this helped!
7 0
3 years ago
Start with the following Python code. alphabet = "abcdefghijklmnopqrstuvwxyz" test_dups = ["zzz","dog","bookkeeper","subdermatog
trapecia [35]

Answer:

alphabet = "abcdefghijklmnopqrstuvwxyz"

test_dups = ["zzz","dog","bookkeeper","subdermatoglyphic","subdermatoglyphics"]

test_miss = ["zzz","subdermatoglyphic","the quick brown fox jumps over the lazy dog"]

# From Section 11.2 of: # Downey, A. (2015). Think Python: How to think like a computer scientist. Needham, Massachusetts: Green Tree Press.

def histogram(s):

   d = dict()

   for c in s:

       if c not in d:

           d[c] = 1

       else:

           d[c] += 1

   return d

#Part 1 Write a function called has_duplicates that takes a string parameter and returns True if the string has any repeated characters. Otherwise, it should return False.

def has_duplicates(stringP):

   dic = histogram(stringP)

   for key,value in dic.items():

       if value>1:

           return True

   return False

# Implement has_duplicates by creating a histogram using the histogram function above. Write a loop over the strings in the provided test_dups list.

# Print each string in the list and whether or not it has any duplicates based on the return value of has_duplicates for that string.

# For example, the output for "aaa" and "abc" would be the following. aaa has duplicates abc has no duplicates Print a line like one of the above for each of the strings in test_dups.

print("***Implementation of has_duplicates fuction***")

for sTr in test_dups:

   if has_duplicates(sTr):

       print(sTr+": has duplicates")

   else:

       print(sTr+": has no duplicates")

#Part 2 Write a function called missing_letters that takes a string parameter and returns a new string with all the letters of the alphabet that are not in the argument string.

#The letters in the returned string should be in alphabetical order. Your implementation should use a histogram from the histogram function. It should also use the global variable alphabet.

#It should use this global variable directly, not through an argument or a local copy. It should loop over the letters in alphabet to determine which are missing from the input parameter.

#The function missing_letters should combine the list of missing letters into a string and return that string.

def missing_letters(sTr):

   missingLettersList = []

   dic = histogram(sTr)

   for l in alphabet:

       if l not in dic:

           missingLettersList.append(l)

   missingLettersList.sort()

   return "".join(missingLettersList)

#Write a loop over the strings in list test_miss and call missing_letters with each string. Print a line for each string listing the missing letters.

#For example, for the string "aaa", the output should be the following. aaa is missing letters bcdefghijklmnopqrstuvwxyz

#If the string has all the letters in alphabet, the output should say it uses all the letters.

#For example, the output for the string alphabet itself would be the following. abcdefghijklmnopqrstuvwxyz uses all the letters

#Print a line like one of the above for each of the strings in test_miss.

print("\n***Implementation of missing_letters fuction***")

for lTm in test_miss:

   sTr = missing_letters(lTm.replace(" ",""))

   if sTr!="":

       print(lTm+" is missing letters "+sTr)

   else:

       print(lTm +" uses all the letters")

3 0
3 years ago
Write, compile, and execute a C program that calculates and returns the fourth root of the number 81.0, which is 3. (hint: The f
alex41 [277]

Answer:

   result=pow(value,0.25);

   printf("The 4th root is:%2.f",result);

Explanation:

In order to accomplish the task we need a library called math.h.

//4 root code

#include <stdio.h>

#include <math.h> //adding the library math.h

int main()

{  

   double value=81.0,root=0.25,result; //declaring the variables

   result=pow(value,root); //The function Pow will return the power raised to the base number

   printf("The 4th root is:%2.f",result); //print the result

   return 0;

}

3 0
3 years ago
PLEASE HELP ASAP!!
Licemer1 [7]

Answer:i They automatically display as the first row or column.

Explanation:Go to the "Insert" tab on the Excel toolbar, and then click the “Header & Footer” button in the Text group to start the process of adding a header. Excel changes the document view to a Page Layout view. Click on the top of your document where it says “Click to Add Header,” and then type the header for your document.

7 0
4 years ago
What is white noise and how does it affect a signal? Provide a business process example that could be affected and what would yo
marin [14]

Answer: White noise is the merging of the audible signal of different frequencies varying from high to low into a single unit. The number of frequencies combined  in white noise more than 20,000. It helps in masking the other noise in the environment.

In accordance with the signal, white noise acts as a statistical mode which merges all the signal into one with same intensity which results in the power spectral density being persistent.

E.g.- Any business process of company that requires attention and speedy working such as creating report, presentation can get affected by the white noise in positive  or negative manner depending on the person.It might lead to increment or decrement in the cognitive performance of employees.

White noise can be remove by several software present in the market, removing it by the "Noise removal" option from the Effects menu in operating system, etc.  

5 0
3 years ago
Other questions:
  • Eric is working on a computer that has a device driver error. Eric can find the name of the device driver however the actual dev
    8·1 answer
  • Which education level has the highest return on investment (ROI)? AHigh School Diploma BROI is equal for all of the above. CSeni
    6·1 answer
  • Write a declaration for a class named City, which has the members cityName, a string, and position, a Location structure (declar
    10·1 answer
  • Leslie is looking for better job opportunities in his current career path. Which career planning guideline would help him as he
    6·2 answers
  • What are the 3 examples of numeral systems
    5·1 answer
  • The measure means to determine the exact size, amount, or distance of something
    11·1 answer
  • Analyze the code and identity the value of variable a,b and c after the code execution. int a=40, b=50, c=60; if(! (a&gt;=40)) b
    15·1 answer
  • Pick one of the following scenarios and
    6·1 answer
  • Write a C console application that will be used to determine if rectangular packages can fit inside one of a set of spheres. You
    5·1 answer
  • Which approach to bandwidth usage consumes all of the available frequencies on a medium to transmit data
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!