Introduction to Java Programming and Data Structures, Comprehensive Version, Student Value Edition (11th Edition)
11th Edition
ISBN: 9780134671604
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.
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.
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
Chapter 4 Solutions
Introduction to Java Programming and Data Structures, Comprehensive Version, Student Value Edition (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
T F: If the CInt function cannot convert its argument, it causes a runtime error.
Starting Out With Visual Basic (7th Edition)
Find the error in each of the following. (Note: There may be more than one error.) The following code should pr...
C How to Program (8th Edition)
What is an algorithm?
Starting Out With Visual Basic (8th Edition)
Write the statement that calls a superclass constructor and passes the arguments x, y, and z.
Starting Out with Java: From Control Structures through Objects (6th Edition)
Given the following fragment that purports to convert from degrees Celsius to degrees Fahrenheit, answer the fo...
Absolute Java (6th Edition)
Celsius and Fahrenheit Temperature Converter Assuming that C is a Celsius temperature, the following formula co...
Starting out with Visual C# (4th 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
- 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 screenshotsarrow_forwardin the programming language java write a method that returns the biggest digit of an integer number. (parameter of the method)arrow_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_forward
- Questions 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_forwardThe 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_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
- b. Evaluate the following method calls. i. Math.sqrt(4) ii. Math.pow(2,2) iii. Math.ceil(-2.5) iv. Math.round(-2.5)arrow_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_forwardConsider the pseudo-code method below: PrintOnes (n) if n == 0 then print("1") else for i = 1 to 3 PrintOnes (n-1) Question 7 of 11 Click to see additional instructions How many times will "1" be printed when the method is called with a parameter of 3? A Questiarrow_forward
- 21. Consider the following method: public static void sketch(int x1, int y1, int x2, int y2, int n) ( if (n <= 0) O else ( } drawLine(x1, y1, x2, y2); Assume that the screen looks like a Cartesian coordinate system with the origin at the center, and that drawLine connects (x1,y1) to (x2,y2). Assume also that x1, y1, x2, and y2 are never too large or too small to cause errors. Which picture best represents the sketch drawn by the method call int xm (x1 + x2 + y1 - y2) / 2; int ym (y1 + y2 + x2-x1) / 2; sketch(x1, y1, xm, ym, n - 1); sketch (xm, ym, x2, y2, n - 1); sketch(a, 0, -a, 0, 2) where a is a positive integer? (A) <-a y -a y a X (B) (D) -a -a y + -a -a aarrow_forwardWrite a recursive method that takes two integer number start and end. The method int evensquare2 (int start, int end) should return the square of even number from the start number to the end number. Then, write the main method to test the recursive method. For example: If start = 2 and end = 4, the method calculates and returns the value of: 22 * 4= 20 If start = 1 and end 2, the method calculates and returns the value of: 22 4 Sample I/O: Enter Number start: 2 Enter Number start: 4 Result = 20 Enter Number start: 1 Enter Number start: 2 Result = 4arrow_forwardExamples of questions • You are maintaining a software and you come across the following method. Comment on its quality by pointing out problems that you see and rewrite the method by fixing them. (Note: Feel free to do the changes in multiple iterations if you find it easier.) public static void f(int[] a) { int t; } for (int p = 0; p a[i+1]){ t = a[i+1]; a[i+1] = a[i]; a[i] = t; }}}arrow_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