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 21

The process of finding the largest value (i.e., the maximum of a group of values) is used frequently in computer applications. For example, a program that determines the winner of a sales contest would input the number of units sold by each salesperson. The salesperson who sells the most units wins the contest. Write a pseudocode program and then a Java application that inputs a series of 10 integers and determines and prints the largest integer. Your program should use at least the following three variables: a) counter: A counter to count to 10 (i.e., to keep track of how many numbers have been input and to determine when all 10 numbers have been processed). b) number: The integer most recently input by the user. c) largest: The largest number found so far.

Problem 29

Write an application that prompts the user to enter the size of the side of a square, then displays a hollow square of that size made of asterisks. Your program should work for squares of all side lengths berween 1 and 20 .

Problem 30

\( { Palindromes })\) A palindrome is a sequence of characters that reads the same backward as forward. For example, each of the following five-digit integers is a palindrome: 12321,55555,45554 and \(11611 .\) Write an application that reads in a five-digit integer and determines whether it is a palindrome. If the number is not five digits long, display an error message and allow the user to enter a new value.

Problem 31

Write an application that inputs an integer containing only 0 s and 1 s (i.e., a binary integer) and prints its decimal equivalent. [Hint: Use the remainder and division operators to pick off the binary number's digits one at a time, from right to left. In the decimal number system, the rightmost digit has a positional value of 1 and the next digit to the left has a positional value of \(10,\) then 100 , then \(1000,\) and so on. The decimal number 234 can be interpreted as \(4^{*} 1+3^{*} 10+2^{*} 100 .\) In the binary number system, the rightmost digit has a positional value of 1 , the next digit to the left has a positional value of \(2,\) then \(4,\) then \(8,\) and so on. The decimal equivalent of binary 1101 is \(1^{*}\) \(1+0^{*} 2+1^{*} 4+1^{*} 8,\) or \(1+0+4+8\) or, 13.1

Problem 33

Write an application that keeps displaying in the command window the multiples of the integer \(2-\) namely, \(2,4,8,16,32,6 \overline{4},\) and so on. Your loop should not terminate (i.e., create an infinite loop). What happens when you run this program?

Problem 34

What is wrong with the following starement? Provide the correct statement to add one to the sum of \(x\) and \(y\) System.out.println( \(++(x+y))\)

Problem 35

Write an application that reads three nonzero values entered by the user and determines and prints whether they could represent the sides of a triangle.

Problem 36

Write an application that reads three nonzero integers and determines and prints whether they could represent the sides of a right triangle.

Problem 37

A company wants to transmit data over the telephone but is concerned that its phones may be tapped. It has asked you to write a program that will encrypt the data so that it may be transmitted more securely. All the data is transmitted as four-digit integers. Your application should read a four-digit integer entered by the user and encrypt it as follows: Replace each digit with the result of adding 7 to the digit and getting the remainder after dividing the new value by \(10 .\) Then swap the first digit with the third, and swap the second digit with the fourth. Then print the encrypted integer. Write a separate application that inputs an encrypted four-digit integer and decrypts it to form the original number.

Problem 38

The factorial of a nonnegative integer \(n\) is written as \(n !\) (pronounced "n factorial") and is defined as follows: \(n !=n \cdot(n-1) \cdot(n-2) \dots \dots 1 \quad \text { (for values of } n \text { greater than or equal to } 1)\) and \\[ n !=1 \quad(\text { for } n=0) \\] For example, \(5 !=5 \cdot 4 \cdot 3 \cdot 2 \cdot 1,\) which is 120 a) Write an application that reads a nonnegative integer and computes and prints its factorial. b) Write an application that estimates the value of the mathematical constant \(e\) by using the formula \\[ e=1+\frac{1}{1 !}+\frac{1}{2 !}+\frac{1}{3 !}+\dots \\] c) Write an application that compures the value of \(e^{x}\) by using the formula \\[ e^{x}=1+\frac{x}{1 !}+\frac{x^{2}}{2 !}+\frac{x^{3}}{3 !}+\ldots \\]

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