Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
11th Edition
ISBN: 9780134670942
Author: Y. Daniel Liang
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Textbook Question
Chapter 4.2, Problem 4.2.1CP
Evalute the following method calls:
- (a) Math.sqrt(4)
- (b) Math.sin(2 * Math.PI)
- (c) Math.cos(2 * Math.PI)
- (d) Math.pow(2, 2)
- (e) Math.log(Math.E)
- (f) Math.exp(1)
- (g) Math.max(2,Math.min(3, 4))
- (h) Math.rint(−2.5)
- (i) Math.ceil (−2.5)
- (j) Math.floor(−2.5)
- (k) Math.round(−2.5f)
- (l) Math.round(-2.5)
- (m) Math.rint(2.5)
- (n) Math.ceil (2.5)
- (o) Math.floor(2.5)
- (p) Math.round(2.5f)
- (q) Math.round(2.5)
- (r) Math.round (Math, abs (-2.5))
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Using METHOD
SAMPLE
Problem:
Create a method that will compute the value of
PI, if pi is 3.14.
Given formula is : value = pi x square of radius
Solution:
float area(int radius)
final float pi = 3.14f;
float val;
val = pi * (float) (radius * radius);
return(val);
Direction: Analyze the given problem and create a java method.
Problem:
Create a method that will compute the Mass (m). Acceleration(a) is 9.80. if Force (F) is equal to
acceleration multiplied by mass.
Consider the following method:
public static void method (int x, int y) {
if (x < y) {
method (x+1, y);
System.out.print (x + " ");
}
}
What will happen as the result of calling method (2,6)? (Select all correct answers)
output will be 6 5 4 3 2
Program goes to an infinite loop because of errors in recursive calls
5 recursive calls will be made from method (3,6) to method (7,6)
output will be 5 4 3 2
method (6, 6) will be called inside of the recursion
4 recursive calls will be made from method (3,6) to method (6,6)
method (5, 6) will be called inside of the recursion
task-5
Change Summation Integers problem to Finding the minimumproblem. Make sure you properly wrote/updated all text messages, method names,and math calculations.Hint: You can use java.lang.Math.min() method.Example: System.out.printf("The min of the integers %4d and %4d and %4dis %7d\n", a, b, c, MinTest(a, b, c));Submit the source code files (.java files) and the console output screenshots
Chapter 4 Solutions
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
Ch. 4.2 - Evalute the following method calls: (a)...Ch. 4.2 - True or false? The argument for trigonometric...Ch. 4.2 - Write a statement that converts 47 degrees to...Ch. 4.2 - Write a statement that converts PI to an angle in...Ch. 4.2 - Write an expression that obtains a random integer...Ch. 4.2 - Prob. 4.2.6CPCh. 4.2 - Prob. 4.2.7CPCh. 4.3 - Use print statements to find out the ASCII code...Ch. 4.3 - Which of the following are correct literals for...Ch. 4.3 - How do you display the characters \ and "?
Ch. 4.3 - Evaluate the following: Int i = '1'; int j ='1' +...Ch. 4.3 - Can the following conversions involving casting be...Ch. 4.3 - Show the output of the following program: public...Ch. 4.3 - Write the code that generates a random lowercase...Ch. 4.3 - Show the output of the following statements:...Ch. 4.4 - Suppose s1, s2, and s3 are three strings, given as...Ch. 4.4 - Prob. 4.4.2CPCh. 4.4 - Show the output of the following statements (write...Ch. 4.4 - Prob. 4.4.4CPCh. 4.4 - Let s1 be " Welcome " and s2 be " welcome ". Write...Ch. 4.4 - Write one statement to return the number of digits...Ch. 4.4 - Write one statement to return the number of digits...Ch. 4.5 - If you run Listing 4.3 GuessBirthday.java with...Ch. 4.5 - If you enter a lowercase letter such as b, the...Ch. 4.5 - What would be wrong if lines 6 and 7 are in...Ch. 4.6 - Prob. 4.6.1CPCh. 4.6 - Prob. 4.6.2CPCh. 4.6 - Show the output of the following statements: (a)...Ch. 4 - (Geometry: area of a pentagon) Write a program...Ch. 4 - (Geometry: great circle distance) The great circle...Ch. 4 - (Geography: estimate areas) Use the GPS locations...Ch. 4 - (Geometry: area of a hexagon) The area of a...Ch. 4 - (Geometry: area of a regular polygon) A regular...Ch. 4 - (Random points on a circle) Write a program that...Ch. 4 - (Corner point coordinates) Suppose a pentagon is...Ch. 4 - (Find the character of an ASCII code) Write a...Ch. 4 - (Find the Unicode of a character) Write a program...Ch. 4 - (Guess birthday) Rewrite Listing 4.3,...Ch. 4 - (Decimal to hex) Write a program that prompts the...Ch. 4 - (Hex to binary) Write a program that prompts the...Ch. 4 - (Vowel or consonant?) Write a program that prompts...Ch. 4 - (Convert Letter grade to number) Write a program...Ch. 4 - (Phone key pads) The international standard...Ch. 4 - (Random character) Write a program that displays a...Ch. 4 - (Days of a month) Write a program that prompts the...Ch. 4 - (Student major and status) Write a program that...Ch. 4 - (Business: check ISBN-10) Rewrite Programming...Ch. 4 - (Process a string) Write a program that prompts...Ch. 4 - (Check SSN) Write a program that prompts the user...Ch. 4 - (Check substring) Write a program that prompts the...Ch. 4 - 23 (Financial application: payroll) Write a...Ch. 4 - (Order three cities) Write a program that prompts...Ch. 4 - (Generate vehicle plate numbers) Assume that a...Ch. 4 - (Financial application: monetary units) Rewrite...
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
Describe the primary differences between the conceptual and logical data models.
Modern Database Management
The 50-mm-diameter cylinder is made from Am 1004-T61 magnesium and is placed in the clamp when the temperature ...
Mechanics of Materials (10th Edition)
The factorial of 0 is defined to be 1. The factorial of a positive integer is defined to be the product of that...
Computer Science: An Overview (13th Edition) (What's New in Computer Science)
T F: If the CInt function cannot convert its argument, it causes a runtime error.
Starting Out With Visual Basic (8th Edition)
The force of F = 30 N acts on the bracket as shown. Determine the moment of the force about the a a axis of th...
INTERNATIONAL EDITION---Engineering Mechanics: Statics, 14th edition (SI unit)
In Exercises 61 through 66, rewrite the statements using augmented assignment operators. Assume that each varia...
Introduction To Programming Using Visual Basic (11th Edition)
Knowledge Booster
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
- Python Programming ONLY PLEASE NO JAVA Use recursion to determine the number of digits in an integer n. Hint: If n is < 10, it has one digit. Otherwise, it has one more digit than n / 10. Write the method and then write a test program to test the method Your test program must: Ask the user for a number Print the number of digits in that number. (describe the numbers printed to the console) Use program headers and method header comments in your code.arrow_forwardin the programming language java write a method that returns the biggest digit of an integer number. (parameter of the method)arrow_forwardQuestions are based on following code; the integer on each line indicates the line number that is not part of the code: 1 public static int sum(int x, int y){ 2 int z = x +y; 3 return z; 4 } 5 public static void main(String[] args){ 6 … 7 sum(a+2, b); 8 … 9 } write the signature of the method sum: sum(int,int) list the local variables of sum: x, y, and y are local variables of the function. list the parameters of sum: int x, int y (write the line numbr where a call to sum happens 7 question2 list the arguments for the above call _____________ question3 list the return type of sum here ___________________ question 2 and 3 confuse me!!arrow_forward
- 12 - question The following method is a recursive pow method to compute exponents, there is a logical error in this code. Please choose the line which has the error. 1. public static int pow (int x, int y) { 2. if (y>1) 3. return x * pow (x, y - 1); 4. else 5. return y; 6. } a. Line 2 b. Line 3 C. Line 4 d. Line 5arrow_forwardtask4-Change Summation Integers problem to Finding the minimumproblem. Make sure you properly wrote/updated all text messages, method names,and math calculations.Hint: You can use java.lang.Math.min() method.Example: System.out.printf("The min of the integers %4d and %4d and %4dis %7d\n", a, b, c, MinTest(a, b, c));Submit the source code files (.java files) and the console output screenshotsarrow_forwardWrite and test the following recursive methods:1. A method that, for a positive integer n, prints odd numbers between 1 and n.2. A method that, for a positive integer n, prints odd numbers between n and 1.3. A method to add the first n terms of the series: 1 +12−13+14−15…1?4. A recursive version of the following method:void cubes(int n) {for (int i = 1; i <= n; i++)System.out.print(i * i * i, " ");}arrow_forward
- The following recursive method has been created. This method accepts two integer parameters called a and b respectively. Assume that the name of the method is m and the code in the recursive method is: if ( a > b ) return; if(a % 10 == 3) System.out.print(a+ " "); m(a+1, b); <---- recursive call } what would be the output with the following call m(1,50) where a is 1 and b is 50arrow_forwardDo not use static variables to implement recursive methods. USING JAVA USING: // P5 public static long computePay(int day) { } You have been offered a job that pays as follows: On the first day, you are paid 1 cent, on the second day, 2 cents, on the third day, 4 cents and so on. In other words, your pay doubles every day. Write a recursive method computePay that for a given day number computes the pay in cents. Assume that you accumulate all the money that you are paid. Write a recursive method computeSavings that computes the sum that you have accumulated on a given day. Show the output of computePay and computeSavings for day number 39.arrow_forwardProblem: Min Method (Return the Smaller Number) Create a method GetMin(int a, int b), which returns the smaller of two numbers. Write a program, which takes as input three numbers and prints the smallest of them. Use the method GetMin(…), which you have already created. Sample Input and Output Input Output Input Output 123 1 -100-101-102 -102 Hints and Guidelines Define a method GetMin(int a, int b) and implement it, after which invoke it from the main program as shown below. In order to find the minimum of three numbers, first, find the minimum of the first two and then the minimum of the result and the third number: var min = GetMin(GetMin(num1, num2), num3);References: Programming Basics with C#: Comprehensive Introduction to Programming with C#: Book + Video Lessons by Dr. Svetlin Ivanov NakovPaperbackarrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Programming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:Cengage
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Introduction to Big O Notation and Time Complexity (Data Structures & Algorithms #7); Author: CS Dojo;https://www.youtube.com/watch?v=D6xkbGLQesk;License: Standard YouTube License, CC-BY