EBK JAVA PROGRAMMING
9th Edition
ISBN: 9781337671385
Author: FARRELL
Publisher: CENGAGE LEARNING - CONSIGNMENT
expand_more
expand_more
format_list_bulleted
Question
Chapter 3, Problem 2PE
Program Plan Intro
Java Method calling:
- The java method is a collection of statements used to perform certain operations.
- The method should be called in order to use it. The methods can be called in two ways,
- Method returning a value
- Methods returning nothing
- The method calling process is very simple. When calling a method, the program control gets transferred to the called method.
- The above stated called method returns control to the caller in two separate conditions. That are,
- The return statement is executed.
- It reaches the closing brace of the method.
- The arguments of the method call should be same as in the definition of the method.
Expert Solution & Answer
Trending nowThis is a popular solution!
Students have asked these similar questions
11
a) Write a boolean method called sumDivisibleByFive that returns true if the sum of the digits of its integer
parameter is divisible by 5 and false otherwise. For example, if the parameter passed to the method is 73
then the sum of its digits is 10 (7+3) The method should return true since 10 is divisible by 5.
b) Write a main method that calls the method sumDivisibleByFive for the values between 10 and 100
inclusive 10 per line. This should output the following numbers:
14 19 23 28 32 3741 46 50 55
64 69 73 78 82 87 91 96
a) Write a boolean method called sumDivisibleByFive that returns true if the sum of the digits of its integer
parameter is divisible by 5 and false otherwise. For example, if the parameter passed to the method is 73
then the sum of its digits is 10 (7+3). The method should return true since 10 is divisible by 5.
b) Write a main method that calls the method sumDivisibleByFive for the values between 10 and 100
inclusive 10 per line. This should output the following numbers:
14 19 23 28 32 37 41 46 50 55
Using java
64 69 73 78 82 87 91 96
Chapter 3 Solutions
EBK JAVA PROGRAMMING
Ch. 3 - Prob. 1RQCh. 3 - Prob. 2RQCh. 3 - Prob. 3RQCh. 3 - Prob. 4RQCh. 3 - Prob. 5RQCh. 3 - Prob. 6RQCh. 3 - Prob. 7RQCh. 3 - Prob. 8RQCh. 3 - Prob. 9RQCh. 3 - Prob. 10RQ
Ch. 3 - Prob. 11RQCh. 3 - Prob. 12RQCh. 3 - Prob. 13RQCh. 3 - Prob. 14RQCh. 3 - Prob. 15RQCh. 3 - Prob. 16RQCh. 3 - Prob. 17RQCh. 3 - Prob. 18RQCh. 3 - Prob. 19RQCh. 3 - Prob. 20RQCh. 3 - Prob. 1PECh. 3 - Prob. 2PECh. 3 - Prob. 3PECh. 3 - Prob. 4PECh. 3 - Prob. 5PECh. 3 - Prob. 6PECh. 3 - Prob. 7PECh. 3 - Prob. 8PECh. 3 - Prob. 9PECh. 3 - Prob. 10PECh. 3 - Prob. 11PECh. 3 - Prob. 12PECh. 3 - Prob. 13PECh. 3 - Prob. 1GZCh. 3 - Prob. 2GZCh. 3 - Prob. 1CP
Knowledge Booster
Similar questions
- Examine the following method header; then write an example call to the method. private void ResetValue(ref int value)arrow_forwardT/F(If false, correct the statement to make it true) - A void method will return an int valuearrow_forwardQUESTION 10 Multiple Choice: What is the return type of the following method? public static void widget(double a, String b){ ... } String void int double QUESTION 11 Multiple Choice: Which statement is true about the method below? public static String doStuff(int x, double n, boolean b){ ... } String is the return type of this method int x, doublen, and boolean b will cause a syntax error and should be moved to the method body public and static are identifiers for the method O doStuff is a modifier for the method QUESTION 12arrow_forward
- 3) The following method should return true if the int parameter is even and either positive or 0, and false otherwise.Which set of code should you use to replace … so that the method works appropriately?public boolean question3(int x) { … }a) if (x = = 0) return true; else if (x < 0) return false; else return question3(x – 1);b) if (x = = 0) return false; else if (x < 0) return true; else return question3(x – 1);c) if (x = = 0) return true; else if (x < 0) return false; else return question3(x – 2);d) if (x = = 0) return false; else if (x < 0) return true; else return question3(x – 2);e) return(x = = 0);arrow_forwarda) Write a boolean method called productDivisibleByThree that returns true if the product of the digits of its integer parameter is divisible by 3 and false otherwise. For example, if the value passed to the method is 23 then the product of its digits is 6 (2*3). The method should retum true since 6 is divisible by 3. b) Write a main method that calls the method productDivisibleByThree for the values between 10 and 50 inclusive 10 per line. This should output the following numbers: 10 13 16 19 20 23 26 29 30 31 Using java 32 33 34 35 36 37 38 39 40 43 46 49 50arrow_forwardPart 4: Methods The following is Java pseudocode. For this exercise, you can assume the input function provides an appropriate integer value. Line numbers are provided on the left. System.out.print will print the information to the same line. System.out.println will print the information and then go to the next line. // is a comment. Do not worry about public static. Code execution starts with the main method. For each method used, make sure to provide a separate table showing what the values are and how they change (i.e. tracing through the code). All variables passed in have values. Don’t worry about showing how the input() method works. 7 public static int test1(int x1, int x2){ 8 9 if(x1==0){ 10 x1=10; 11 } 12 if(x2==0){ 13 x2=10 14 } 15 16 return x1*x2; 17 } 18 19 public static int test2(int x2, int x1){ 20 return x2-x1; 21 } 22 public static int input(){…arrow_forward
- c# Previously , you wrote a program named Hurricane that classified hurricanes into five categories using the Saffir-Simpson Hurricane Scale. Now, create a modified version named HurricaneModularized that passes a user’s input wind speed to a method that returns the hurricane category. using System; using static System.Console; class Hurricane { static void Main() { // Write your main here. } public static int GetCategory(int wind) { // Write your GetCategory method here. } }arrow_forward2) Two integers are said to be relatively prime if their greatest common divisor (GCD) is one. For example 12 and 13 are relatively prime, but 12 and 14 are not. a. Write a method called relativelyPrime that accepts two integer parameters A and B. The method should output if A, and B are relatively prime or nat. Use the following method header: public static void relativelyPrime(int A, int B) b. Write a test program (main) to test the method by asking the user to input two positive integers X and Y. Then the program will call the method relativelyPrime to output if X and Y are relatively prime or not. Sample Run 1: Enter Two positive integers X and Y: 12 13 12 and 13 are relatively prime Sample Run 2: Enter Two positive integers X and Y: 12 14 12 and 14 are not relatively primearrow_forwardInstructions Write a program that simulates a simple calculator. This calculator is limited to the following functions: Addition Subtraction Multiplication Division Your program requires a total of 6 methods (INCLUDING THE MAIN) These methods are listed and explained below: o The main method which will perform the following actions: ► Declare necessary variables (number1, number2, choice, answer) Welcome the user Prompt for the first number (double) ➤ Prompt for the second number (double) Prompt for the arithmetic choice (int) Validate the choice prompt using a do while loop (1-4 are VALID entries) Create ONE control structure to determine which method to call based on users input to choice variable ➤ Call display Results method passing the answer variable to display the answer. o Four methods of type double which take as arguments the users two doubles and returns the appropriate calculation. Hint these methods will all be very similar, apart from the math. public static double…arrow_forward
- Given the method's header public static void doSomething(int a, int b) The following is an invalid statement in the method doSomething. (Select all that apply) A) return b; B) System.out.println(b + a); C) double a; D) double y = a * b;arrow_forwardThis appears at the beginning of a method definition.a. semicolonb. parenthesesc. bodyd. headerarrow_forwardUrgent Answer Have a nice day:)arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781305480537Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTEBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,
- Programming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:CengageC++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781305480537
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning