EBK BUILDING JAVA PROGRAMS
EBK BUILDING JAVA PROGRAMS
4th Edition
ISBN: 9780134323718
Author: Stepp
Publisher: PEARSON CUSTOM PUB.(CONSIGNMENT)
bartleby

Concept explainers

bartleby

Videos

Textbook Question
Book Icon
Chapter 4, Problem 1E

Write a method called fractionSum that accepts an integer parameter n and returns as a double the sum of the first n terms of the sequence

i = 1 n 1 i

In other words, the method should generate the following sequence:

1 + 12 + 13 + 14 + 15 +

You may assume that the parameter n is nonnegative.

Expert Solution & Answer
Check Mark

Explanation of Solution

Given code snippet:

  //define the static function

        public static double fractionSum(int n) {

            //declare the required variables

            int denominator = 1;

            double sum = 0.0;

            //loop to generate the sequence

            for (int i = 1; i <= n; i++) {

                //evaluate the value

                sum += (double) 1 / denominator;

                //increment the value

                denominator++;

            }

            //return statement

            return sum;

        }

Explanation to the above code snippet:

  • In the above code, the static method named “fractionSum” is defined.
  • Required variables are declared and initialized.
  • For loop is initialized to generate the required sequence.
  • Evaluate the value and store it in the variable “sum”.
  • The value stored in the variable “sum” is returned.

Want to see more full solutions like this?

Subscribe now to access step-by-step solutions to millions of textbook problems written by subject matter experts!
Students have asked these similar questions
2.68♦♦ Write code for a function with the following prototype: * Mask with least signficant n bits set to 1 * Examples: n = 6 -> 0x3F, n = 17-> 0x1FFFF * Assume 1 <= n <= w int lower_one_mask (int n); Your function should follow the bit-level integer coding rules Be careful of the case n = W.
Hi-Volt Components You are the IT manager at Hi-Voltage Components, a medium-sized firm that makes specialized circuit boards. Hi-Voltage's largest customer, Green Industries, recently installed a computerized purchasing sys- tem. If Hi-Voltage connects to the purchasing system, Green Industries will be able to submit purchase orders electronically. Although Hi-Voltage has a computerized accounting system, that system is not capable of handling EDI. Tasks 1. What options does Hi-Voltage have for developing a system to connect with Green Industries' pur- chasing system? 2. What terms or concepts describe the proposed computer-to-computer relationship between Hi-Voltage and Green Industries? why not? 3. Would Hi-Voltage's proposed new system be a transaction processing system? Why or 4. Before Hi-Voltage makes a final decision, should the company consider an ERP system? Why or why not?
Consider the following expression in C: a/b > 0 && b/a > 0.What will be the result of evaluating this expression when a is zero? What will be the result when b is zero? Would it make sense to try to design a language in which this expression is guaranteed to evaluate to false when either a or b (but not both) is zero? Explain your answer

Chapter 4 Solutions

EBK BUILDING JAVA PROGRAMS

Additional Engineering Textbook Solutions

Find more solutions based on key concepts
What types of polymers are most commonly blow molded?

Degarmo's Materials And Processes In Manufacturing

What is an uninitialized variable?

Starting Out with Programming Logic and Design (5th Edition) (What's New in Computer Science)

How does a computers main memory differ from its auxiliary memory?

Java: An Introduction to Problem Solving and Programming (8th Edition)

What types of coolant are used in vehicles?

Automotive Technology: Principles, Diagnosis, And Service (6th Edition) (halderman Automotive Series)

Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781305480537
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Text book image
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Java Math Library; Author: Alex Lee;https://www.youtube.com/watch?v=ufegX5o8uc4;License: Standard YouTube License, CC-BY