Warning: foreach() argument must be of type array|object, bool given in /var/www/html/web/app/themes/studypress-core-theme/template-parts/header/mobile-offcanvas.php on line 20

Problem 14

Write a method integerPower ( base, exponent ) that returns the value of ? base exponent For example, integerPower (3,4) calculates \(3^{4}(\text { or } 3 * 3 \text { in } 3 * 3) .\) Assume that exponent is a positive, nonzero integer and that base is an integer. Method integerPower should use a for or while statement to control the calculation. Do not use any math library methods. Incorporate this method into an application that reads integer values for base and exponent and performs the calculation with the integerPower method.

Problem 17

Write a method isEven that uses the remainder operator (\%) to determine whether an integer is even. The method should take an integer argument and return true if the integer is even and \(\left.f_{\mathrm{a}}\right\rceil_{\mathrm{se}}\) otherwise. Incorporate this method into an application that inputs a sequence of integers (one at a time) and determines whether each is even or odd.

Problem 18

Write a method square0fAsterisks that displays a solid square (the same number of rows and columns) of asterisks whose side is specified in integer parameter side. For example, if side is 4, the method should display Incorporate this method into an application that reads an integer value for side from the user and outputs the asterisks with the squareOfAster'sks method:

Problem 20

Write an application that prompts the user for the radius of a circle and uses a method called circleArea to calculate the area of the circle.

Problem 21

Write program segments that accomplish each of the following tasks: a) Calculate the integer part of the quotient when integer a is divided by integer b. b) Calculate the integer remainder when integer a is divided by integer b. c) Use the program pieces developed in parts (a) and (b) to write a method display Digits that receives an integer between 1 and 99999 and displays it as a sequence of digits, separating each pair of digits by two spaces. For example, the integer 4562 should appear as 4 5 6 2 d) Incorporate the method developed in part (c) into an application that inputs an integer and calls displayDigits by passing the method the integer entered. Display the results.

Problem 22

Implement the following integer methods: a) Method Celsius returns the Celsius equivalent of a Fahrenheit temperature, using the calculation Celsius = 5.0 / 9.0 * ( fahrenheit - 32 ); b) Method fahrenheit returns the Fahrenheit equivalent of a Celsius temperature, using the calculation fahrenheit = 9.0 / 5.0 * Celsius + 32; c) Use the methods from parts (a) and (b) to write an application that enables the user either to enter a Fahrenheit temperature and display the Celsius equivalent or to enter a Celsius temperature and display the Fahrenheit equivalent.

Problem 23

Write a method minimum 3 that returns the smallest of three floating-point numbers. Use the Math.min method to implement minimum 3. Incorporate the method into an application that reads three values from the user, determines the smallest value and displays the result.

Problem 24

An integer number is said to be a perfect number if its factors, including 1 (but not the number itself, sum to the number. For example, 6 is a perfect number, because \(6=1+2+3 .\) Write a method perfect that determines whether parameter number is a perfect number. Use this method in an application that determines and displays all the perfect numbers between 1 and \(1000 .\) Display the factors of each perfect number to confirm that the number is indeed perfect. Challenge the computing power of your computer by testing numbers much larger than 1000 , Display the results.

Problem 25

An integer is said to be prime if it is divisible by only 1 and itself. For example, 2,3,5 and 7 are prime, but 4,6,8 and 9 are not: a) Write a method that determines whether a number is prime. b) Use this method in an application that determines and displays all the prime numbers less than \(10,000 .\) How many numbers up to 10,000 do you have to test to ensure that you have found all the primes? c) Initially, you might think that \(n / 2\) is the upper limit for which you must test to see whether a number is prime, but you need only go as high as the square root of \(n .\) Why? Rewrite the program, and run it both ways.

Problem 26

Write a method that takes an integer value and returns the number with its digits reversed. For example, given the number 7631, the method should return 1367. Incorporate the method into an application that reads a value from the user and displays the result.

Access millions of textbook solutions in one place

  • Access over 3 million high quality textbook solutions
  • Access our popular flashcard, quiz, mock-exam and notes features
  • Access our smart AI features to upgrade your learning
Get Vaia Premium now
Access millions of textbook solutions in one place

Recommended explanations on Computer Science Textbooks