The goal of the following method is to calculate and return the average of four integers given as parameters. What is wrong in this method? *
Q: The following method attempts to return the median (middle) of three integer values, but it contains…
A: If we have inputs like n1=3, n2=2 and n3=1 Then the output of program will be 1 which is wrong.
Q: A method named reverse that takes an integer and returns the reversal of the passed integer. The…
A: code : import java.util.Scanner;public class Main { /** Main Method */ public static void…
Q: A method may accept any number of values, including zero O True O False
A: True
Q: What is wrong with the following code, which attempts to return the number of factors of a given…
A: Step 1:- we have to add the count1 variable to the given code to find out total number of factor.…
Q: Given the following method static void printChar (Char ch, int n) { for (int=1; i<-n; i++)…
A: When method is called, ch will be A and n will be 3
Q: The statement used to invoke the following method is public static int max(int num1, int num2) {…
A: the statement that is used to invoke the max method is detailed in step 2.
Q: Can the percentage of completion in the WA Method be above 100%?
A: Can the percentage of completion in the WA Method be above 100%? in below step
Q: For each call to the following method, indicate what value is returned: public int mystery4(int x,…
A: // Online C++ compiler to run C++ program online#include <iostream>using namespace std;int…
Q: What would be wrong with not writing a return statement in a value-returning method? Can you have a…
A: When a method has a return value, it needs to return some value or else it will cause error. A void…
Q: 4. write a method called print which print employee information. C#
A: Print way to help your prove the point, you want to add document and make the page to search online.…
Q: Assume that you are not able to perform other operations on an int value thanto decrement it and…
A: Program code: //include required header files #include <iostream> using namespace std;…
Q: Write a method called method4 that accepts an integer parameter n and returns a sum of the first n…
A: import java.util.Scanner; public class Tester{ public static void main(String[] args) { Scanner…
Q: Write a method (just the method, not the entire program) which does the following public int…
A: Java allows generating random numbers using java.util.Random class. To generate random numbers, we…
Q: What is the result of running the following code (pick the single best answer)? int Answer, x[7] =…
A: I have provided a solution with justification below.
Q: Salina wants to create a method that accept three arguments and find the sum of these three…
A: Requirements:- Salina wants to create a method that accepts three arguments and finds the sum of…
Q: Write a method which accepts 3 integer parameters and returns their average.
A: float avg(int x, int y, int z){ return (float)((x+y+z)/2);}
Q: Again same mistake, please make separate method, don't mess up with main method. Java program for…
A: Please find the answer below :
Q: We discussed and did an example of the Quadratic formula in class. Here is the code for the method…
A: Code: using System;using System.Collections.Generic;using System.Linq;using System.Text;using…
Q: What is the value returned from the following method when it is called with the value 5? int mystery…
A: concept used:- recursion a function call itself again and again until a terminating condition is…
Q: If the value passed into the parameter x in the following method is 10. What is the value returned…
A: 3840 First it will take x as 10 Here i=10;10>0 so true enter into for block Y=1*10 = 10 now…
Q: in the programming language java write a method that returns the biggest digit of an integer number.…
A: Program plan: 1) Take a number input from user. 2) Make a parameterized function taking integer…
Q: Which of the following is a correct method call to the below method: /**
A: Here from the method definition, method calcMPG is returning a double value. Thus we need a double…
Q: This program will determine if a number is divisible by 5 or not. This should be a simple task by…
A: Program approach: import necessary packages required to handle input mismatch exception and scanner…
Q: Write the method isEven that returns true when its argument is even. Your solution can have only a…
A: Since no programming language is mentioned, I am using c++ Algorithm: Start Define a method…
Q: sufficient for testing another method can be used? O None of the other answers are correct O empty…
A: Here have to determine correct option for testing functions.
Q: Remember the Collatz function? If x is odd, then collatz(x) = 3.x +1 but if x is even then…
A: def collatz(num): if num % 2 == 0: return num // 2 else: return 3 * num + 1…
Q: Write a public method named findSum that takes a a parameter named n of type int. If n is less than…
A: The loop executes from i=1 to n and the same term n(n+1)(n+1)/2 is added for n times
Q: Which of the following is true for a method have int return type? a)The method can have only one…
A: Method is the set of code that work together when the programmer call the function. Each method have…
Q: What is the time complexity of the following method? * int method (int n, int m) { int result =0;…
A: The outer for loop will run from 0 to n which means it will run order of n times that is O(n). The…
Q: add Create a method called add that takes two integers as parameters. return the numbers added…
A: Code : import java.util.Scanner; public class SumOfNumbers2 { public static void main(String…
Q: Write a method that returns the lcm (least common multiple) of an unspecified number of integers.…
A: LCM: LCM stands for least common multiple. For example- The lcm of 4 and 6 is the least common…
Q: If the value passed into the parameter x in the following method is 28. What is the value returned…
A: The given program has function method2() which accepts an integer as a parameter, performs…
Q: 2. Write two (2) overloaded methods that will compute the total price of an item. Use the total item…
A: Step-1: Start Step-2: Create a class Program Step-2.1: Create a function priceOfItems and item &…
Q: Can you invoke the max method with an int value and a double value, such as max(2, 2.5)?
A: Yes, the max method can be invoked with an int value and a double value, such as max(2,2.5)
Q: Write the method named countChar()
A: Answer countChar() funtion public int countChar(String str, char ch) { int res = 0;…
Q: What is wrong with the following code? How would you fix it? public static returnTrue(boolean b){…
A: A Boolean expression is an expression of Java that returns a Boolean value: true or false.
Q: T/F 2) There is no base case in the following method. public int noBaseCase(int x) { if(x > 0)…
A: Given that, There is no base case in the following method. public int noBaseCase(int x){if(x >…
Q: If the value passed into the parameter x in the following method is 20. What is the value returned…
A: public static int method3(int x) It receive the value of 20 and store it on x int sum = 0;…
Q: True or false? A call to a method with a void return type is always a statement itself, but a call…
A: A method can be pronounced without any boundaries. Every Java class should contain a principle…
Q: Write a method to read 10 numbers, calculate their sum and display it to user. Use: void sum10();…
A: As given, we need to write a Java program having a method called sum10() to read 10 numbers,…
Q: Find and correct error(s) in the following method definition: public static void doubleNum (int x)…
A: Hey, since multiple questions posted, we will answer first question according to our policy. If you…
Step by step
Solved in 2 steps
- Define a Static method 'max' with return type as 'int' in class 'ProblemSolution' that take two numbers with type 'int'. Inside the 'max' method, compare the two numbers and return the maximum of the two numbers. Then, inside the 'main' method. Define two 'int' type numbers; the first number (num1) is equal to 5 and the second number (num2) is equal to 2. At the next line, call the 'max' method where its parameter input are the two numbers above, and assign the result of the method to the variable num3 (type 'int'). Finally, on the next line, print out -> "The maximum of " + num1 + " and " + num2 + " is " + num3 Output The maximum of 5 and 2 is 5 Where, There must be space between all the words and numbers. There should not any space after the last numberWrite a method called drawDiamond() that outputs lines of '*' to form a Diamond with equal length diagonals. Method drawDiamond() has one parameter, an integer representing the diagonal of the diamond. Assume the diagonal length is always odd and less than 20. Output 9 spaces before the first '*' on the first line for correct formatting. Either drawTriangle or at least one of its helper methods must be recursive. Ex: If the input of the program is: 3 the method drawDiamond() outputs: * *** * Ex: If the input of the program is: 15 the method drawDiamond() outputs: * *** ***** ******* ********* *********** ************ *************** ************* *********** ********* ******* ***** *** * Note: the diamond is made up of a rightside up triangle and an upside down triangle. import java.util.Scanner; public class LabProgram { /* TODO: Write drawDiamond() method here. */ /* You can add other helper methods if needed…. Embed your method in a complete program that requests for three variables all of the types int and displays the conditions explained in “b” above.
- Write a program that calls methods for each of the following mini problems from its main method. Us a single Scanner for the program declared in the class asprivate Static Scanner keyboard = new Scanner(System.in); Repeat the calorie counting program from problem 5 in a new method. This time ask the user to input the string “M” if the user is a man and “W” if the user is a woman. Use only the male formula to calculate calories if “M” is entered and use only the female formula to calculate calories if “W” is entered. Output the number of chocolate bars to consume as before. 2. For all of the following words, if you move the first letter to the end of the word, and then spell the result backwards you will get the original word:banana dresser grammar potato revive uneven assessWrite a method that reads a word and determines whether it has this property. Continue reading and testing words until you encounter the word quit. Treat uppercase letters the same as lowercase letters.…Given an integer N, implement a Static method 'solution' with return type as 'void' in class 'ProblemSolution' displays N for N times. Input 7 Output 7 7 7 7 7 7 7 Where, There must be single space between 2 numbers. There should not any space after the last number. Assume that, N is within the range [0 to 10000].What will be returned from the following method? public double testing ( ) { double a = 9.5 + 9.3; return a; } a) 18.8 b) 18.0 c) 18 d) 19
- Define a static void method, which receives as an parameter an array of salaries (of type double) and increases them as follows • salaries <$ 800 - by 10% • 800 <= salaries <= $1500 - by 5% • salaries over $1,500 - by 3% In the test function, define an initialized array of salaries and display it. Call the written method and display the array again.Write a method checks if a given matrix is a unit matrix. An N x N unit matrix is a matrix of N rows and N columns where all the diagonal elements are ‘1’s and all the remaining elements are ‘0’s. The method should take a 2D array of integers as argument and return a Boolean which is true/false depending on whether the matrix corresponding to the 2D array is a unit matrix or not. Test the method in the ‘main’ method. For problems asking for 'methods', you need to write the method, and the 'main' method which is used as a 'driver' to test the given method.Problem: To write the JUnit test cases for our methods, you need to create two test methods: testLeapYear: This method should test if the isLeapYear method returns true for a given leap year. For example, you can choose the year 2020 and verify if the method returns true for it. If it does, the test will pass. If it doesn't, the test will fail. testNotLeapYear: This method should test if the isLeapYear method returns false for a given non-leap year. For example, you can choose the year 1900 and verify if the method returns false for it. If it does, the test will pass. If it doesn't, the test will fail. --------------------------------------------------------------------------------------------------------------------------------------------------------- import static org.junit.jupiter.api.Assertions.assertTrue; import org.junit.jupiter.api.Test; public class LeapYearTest { // Test case to check if a year is a leap year @Test public void testLeapYear() { //create…
- In Public Class, create a static void method called Info_AHW that takes 3 parameters - an int and two double. When the method is called, we pass along the age (A), then the height (H), and then the weight (W), which is used inside the method to print the person's age, then the height and then the weight. NOTE: The Print out must follow the output below Afterward, in the main method, get the User input using the Scanner class to get the three input - the int age, the double height and the double weight. Then, call your Info_AHW method and pass your arguments (age, height, weight) into that method. Hint: When getting the int input, use -> sc.nextInt(); When getting the double input, use -> nextDouble(); Input: 5 65.5 70.2 Output: Your age is 5 ; your height is 65.5 ; and your weight is 70.2 Note: -There is a single space between every word and semicolon -There is no space at the endAssume that we want to swap the values of two integer -variables, a andb. To do this, we write a method public void swap(int i1, int i2){int tmp = i1; i1 = i2; i2 = tmp;}Then we call this method with our a and b variables:swap(a, b);Are a and b swapped after this call? If you test it, you will notice that they are not! Why does this not work? Explain in detail.Define a method findEmployeeTax() that takes two integer parameters as a person's salary and the number of dependents, and returns the person's tax percent as a double. The tax percent is returned as follows: Salary ≤ 1 dependent 2 - 5 dependents ≥ 6 dependents < 450000 0.15 0.05 0 450000 - 824999 0.25 0.15 0.15 ≥ 825000 0.4 0.25 0.25 Ex: If the input is 425000 0, then the output is: 0.15 import java.util.Scanner; public class TaxFinder { public static double findEmployeeTax(int salary, int numDepen) { double i; if (salary < 450000) { if(numDepen <= 1) i = 0.15; else if (numDepen >= 2 && numDepen <= 5) i = 0.05; else if (numDepen >= 6) i = 0; } else if (salary >= 450000 && salary <= 824999) { if(numDepen <= 1) i = 0.25; else if (numDepen >= 2 && numDepen <= 5) i = 0.15; else if (numDepen >= 6) i = 0.15; } else if…