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
baherus
26 days ago
5

Write the definition of a function power_to, which receives two parameters. The first is a float and the second is an integer. T

he function returns a float. If the second parameter is negative, the function returns zero. Otherwise it returns the value of the first parameter raised to the power of the second.
Computers and Technology
1 answer:
Amiraneli [921]26 days ago
3 0

Answer:

  1.    public static double power_2(double num1, int num2){
  2.        if(num2<0){
  3.            return 0;
  4.        }
  5.        else{
  6.            double returnedVal = Math.pow(num1,num2);
  7.            return returnedVal;
  8.        }
  9.    }

Explanation:

  • This function is written in Java.
  • Line 1 indicates the method definition that specifies it will return a double precision floating point number and takes two parameters: one double and one int as required.
  • Line 2 checks if the second parameter is negative, using an if statement, returning 0.0 if this condition is met.
  • Lines 5-7 create an else clause that calls the Math.pow method to raise num1 to the power of num2 and returns that value.
You might be interested in
What feature would be used to collect how many times users downloaded a product catalog?
ivann1987 [930]
Event Tracking is an important capability within Google Analytics used to capture user interactions with various website elements.
8 0
11 days ago
You work in the educational software industry. Your boss asks you to give a brief lecture to other employees about the digital d
Harlamova29_29 [932]
Joe mama is the most extraordinary person on the planet.
5 0
24 days ago
Read 2 more answers
Write a program that reads a list of words. Then, the program outputs those words and their frequencies. The input begins with a
8_murik_8 [892]

Answer:

Below is the JAVA program:

import java.util.Scanner;   //to take input from user

public class Main {  //name of the class

  public static void main(String[] args) {  //beginning of main method

      Scanner input = new Scanner(System.in);  //creates Scanner instance

      int integer = input.nextInt();  //defines and collects an integer for the number of words

      String stringArray[] = new String[integer]; //initializes an array to hold strings

      for (int i = 0; i < integer; i++) {  //iterates through the array

          stringArray[i] = input.next();         }  //collects strings

      int frequency[] = new int[integer];  //creates an array for holding frequencies

      int count;         //initializes variable to calculate frequency of each word

      for (int i = 0; i < frequency.length; i++) {  //iterates through frequency array

          count = 0;  //sets count to zero

          for (int j = 0; j < frequency.length; j++) {  //iterates through array

              if (stringArray[i].equals(stringArray[j])) {  //checks if element at ith index matches jth index

                  count++;                 }            }  //increments count

          frequency[i] = count;      }  //stores count in the frequency array

      for (int i = 0; i < stringArray.length; i++) {  //iterates through the string array

          System.out.println(stringArray[i] + " " + frequency[i]);         }    }    } //displays each word and its frequency

Explanation:

To illustrate the program, consider:

let integer = 3

for (int i = 0; i < integer; i++) is used to input strings into stringArray.

On the first pass:

i = 0

0<3

stringArray[i] = input.next(); takes a word and saves it to the ith index of stringArray. For example, if the user types "hey", it will be in stringArray[0].

Then, i increments to i = 1

On the second pass:

i = 1

1<3

stringArray[i] = input.next(); takes another word and assigns it to stringArray[1]. If the user enters "hi", then hi will be in stringArray[1]

Next, i becomes i = 2

On the third pass:

i = 2

2<3

stringArray[i] = input.next(); captures a word and places it in stringArray[2]. If the user types "hi", it goes to stringArray[2]

Then, i increments to i = 3

The loop terminates since i<integers is false.

The next outer loop for (int i = 0; i < frequency.length; i++) and inner loop for (int j = 0; j < frequency.length; will check each word and if (stringArray[i].equals(stringArray[j])) identifies any duplicates. Words that repeat will have their count incremented and the frequency array will record these values. For example, hey appears once while hi shows up twice, thus resulting in the final outputs:

hey 1

hi 2

hi 2

The visual representation of the program and its outcome based on the example provided is attached.

4 0
1 month ago
A large organization is struggling to close the gaps in skill levels that exist between its employees and those from competing c
ivann1987 [930]

Answer:

C.) by enabling employees to train and enhance skills for more advanced work

Explanation:

Hope this provides assistance!

3 0
24 days ago
Which of the following best describes how computing devices represent information? A. A computer will either represent informati
oksian1 [797]

Answer:

The answer is B.

Explanation:

The justification for choosing B is that "bytes" represent the correct method for storing data in binary form of 0s and 1s.

5 0
1 month ago
Read 2 more answers
Other questions:
  • Accenture is helping a large retailer transform their online sales and services. The Data Analyst audits the client’s customer j
    12·1 answer
  • 6. Write pseudo code that will perform the following. a) Read in 5 separate numbers. b) Calculate the average of the five number
    6·1 answer
  • This program outputs a downwards facing arrow composed of a rectangle and a right triangle. The arrow dimensions are defined by
    15·1 answer
  • Charlie has a large book collection. He was keeping track of it in a spreadsheet, but it has grown big enough that he wants to c
    10·1 answer
  • Marien is using the Council of Science Editors (CSE) style guidelines to write her research paper. What is her most likely topic
    13·1 answer
  • When a CPU executes instructions as it converts input into output, it does so with
    12·1 answer
  • array of String objects, words, has been properly declared and initialized. Each element of words contains a String consisting o
    11·1 answer
  • This question involves a simulation of a two-player game. In the game, two simulated players each start out with an equal number
    7·1 answer
  • A router has a valid operating system and a configuration file stored in nvram. the configuration file contains an enable secret
    10·1 answer
  • What problem does the DNS solve? How does the DNS help the world wide web scale so that billions of users can access billions of
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!