2. A pentagonal number is defined as n(3n-1)/2 for n = 1, 2, ..., etc.. Therefo the first few numbers are 1, 5, 12, 22, . . . . Write a method with the following header that returns a pentagonal number: public static int getPentagonalNumber(int n)
Q: Q1. Write a String method called "isEven" that takes n as parameter of integer type, and returns…
A: NOTE: We’ll answer the first question since the exact one wasn’t specified. Please submit a new…
Q: Using Java, Write a method named isEven that accepts an int argument. The method should return true…
A: Task :- Write a java program to check if given number is even or not. Java program :- import…
Q: public static boolean isPrime(int number) public static void printPrime(int x) - printPrime method…
A: Sample Output: 2 3 5 7 11 13 17 19 23 29 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73…
Q: Write a method that takes a String name parameter. The method asks the user to input an hour value.…
A: The method accepts a String which is name It prompts user for hours If hours<12 then it's morning…
Q: a) Write a boolean method called sumDivisibleByFive that returns true if the sum of the digits of…
A: Both questions are solved in one problem and programming language are not mentioned in the problem…
Q: Part I Write a method that takes two parameters: integer n, char operation. If the given operation…
A: According to the asked question, the solution is given below with a proper explanation.
Q: 2. Write a program that simulates tossing a coin. Prompt the user for how many times to toss the…
A: 2. Write a program that simulates tossing a coin. Prompt the user for how many times to toss the…
Q: Java Programming. Needs to be done with loops. Define a public static method called…
A: Syntax: do { // Loop-body } while ( Condition ) ; Flowchart:
Q: (Math: pentagonal numbers) A pentagonal number is defined as n(3n-1)/2 for n= 1,2, ..., and so on.…
A: Program description: The java class, PentagonDriver.java is to display the 100 pentagon numbers for…
Q: a) Write a method that calculates the result of the following formula: x² + (x + k}°+ (x + 2k) + (x…
A: The code in java has been given in step 2.
Q: Part I Write a method that takes two parameters: integer n, char operation. If the given operation…
A: Required:
Q: Write a program, named UpdatedNumbers with the following method: Write a method to
A: Since programming language not mentioned using Java language
Q: Consider the following method header, and then write a call to this method that passes the integer…
A:
Q: Class: DoubleMethod Write a method using the header below public static double…
A: Here in this program, I have completed the method which will take a prompt as an argument and return…
Q: Exercise 3 The following two methods are supposed to compute the absolute value of 1 number and the…
A: Given:
Q: In computational geometry, often you needto find the rightmost lowest point in a set of points.…
A: A Java program is as follows, File name: “Sample.java” import java.util.Scanner; public class Sample…
Q: 1. For this part you need to use the floor method and max methods in the Match class. Moreover,…
A: Here I have declared 2 variables min and max to store the range of numbers, and then I have used…
Q: 1. Write the following method that display the result of the following serie 1 1 R ==+=+..+ 3 5 1 2…
A: The Java program reads the value of n from the user. Then call the function with one parameter that…
Q: Write a method with the following header to display threenumbers in decreasing order:public static…
A: Since you are not mentioning the programming language, here we are using Java to complete the…
Q: public static int methodl(int x, int y) { int z 三 02 for (int i = x; i <= y i++) += 3; return 2;
A: public static int method1(int x, int y) { int z = 0; int min = x < y? x : y; int max = x…
Q: A prime number is a number that is only evenly divisible by itself and 1. For example, the number 5…
A: I give the code in Java along with output and code screenshot
Q: An integer number is said to be a perfect number if its factors, including 1 (but not the number…
A: PROGRAM CODE: import java.util.Scanner;public class Main { //creating scanner object to get…
Q: Twin prime numbers, the difference between them is 2. Write a method that prints all duplicate…
A: Read the limit n. For i to n: Check which numbers are prime. then for those prime numbers, Check…
Q: The bark method below is intended to print the string "woof" a total of num times. public static…
A: There is no correct option from the given options.
Q: Write a method that returns n! given an integer n. Your method must use and return a BigInteger…
A: From the given data, We need to write a method that returns n! given an integer n and the method…
Q: Consider the cheers method given above. What is the maximum number of "open" (i.e. incomplete)…
A: Two incomplete methods will be there after calling cheers(3) .
Q: Write a method that returns a random number from alist of numbers passed in the argument. The method…
A: Programming instructions: Create a class RandomNumber. In the main method, call the method…
Q: I have to write a method with the header: public void duplicateTheBag() This method copies the…
A: Algorithm: Start Read size of bag n Read content into bag in an array Define a method…
Q: Write a method thatcomputes future investment value at a given interest rate for a specified…
A: Programming instructions: Import necessary header files. Create a class. Create required variables.…
Q: ISP- Java A pedometer treats walking 2,000 steps as walking 1 mile. Write a program whose input is…
A: Algorithm: Start Implement a method stepsToMiles() which takes userSteps as input and returns…
Q: ISP- JAVA A “jiffy” is the scientific name for 1/100th of a second. Given an input number of…
A: A “jiffy” is the scientific name for 1/100th of a second. 1 second = 100 jiffies read the seconds…
Q: For each call of the method below, display the value that is returned public int retVal(int a, int…
A: Given: For each call of the method below, display the value that is returned public int retVal(int…
Q: Write a method that returns the number of days in ayear using the following header:public static int…
A: 1. There are only two total numbers of days in a year possible. 365 days and 366 days. 2. The total…
Q: There are several techniques for implementingthe sqrt method in the Math class. One such technique…
A: The method sqrt has to be created such that it will use the Babylonian method of computing the…
Q: A regular polygon is an n-sided polygonin which all sides are of the same length and all angles have…
A: Program: //header file import java.util.Scanner; //definition of main class public class Main {…
Q: a) Write a boolean method called sumDivisibleByFive that returns true if the sum of the digits of…
A: Algorithm: Start Implement a method named sumDivisibleByFive() which takes a number n as argument…
Q: Write a method named isPrime, which takes an integer as an argument and returns true if the…
A: No need to check till ending number It's enough you check till square root of a number as the…
Q: All the animals are having a feast! Each animal is bringing one dish. There is just one rule: the…
A: Since no programming language has been specified, I have written a java code down in step 2.
Q: A cashier in a supermarket returns change to customers. Suppose we want to write a program to help…
A: Actually, Java is a programming language originally developed by James Gosling at Sun Microsystems…
Q: 1. Write a program that will ask the a user a number between 1 to 7. 2. Print out the equivalent…
A: The below given C++ program will obey the following rubrics: Including the necessary header file.…
Q: In your program, write a method that accepts a positive integer and returns true if the number is a…
A: C# program: Part1: public Boolean isPrime(int prime) { for (int number =…
Q: 1. Write the following method that display the result of the following serie 1 1 1 R =+=+..+ 3'5 2 n…
A: NOTE: We’ll answer the first question since the exact one wasn’t specified. Please submit a new…
Q: A cashier in a supermarket returns change to customers. Suppose we want to write a program to help…
A: The objective is to write a method that receive the amount of change to be paid to the customer and…
Q: The area of a pentagon can be computed usingthe following formula: Write a method that returns the…
A: Objective: The program determines the area of a pentagon using the formula, area =…
Q: A constructor that creates a regular polygon with the specified number of sides, length of side, and…
A: A constructor has the same name as the class. It is used to initialize objects as they are created.…
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 3 steps with 1 images
- A pentagonal number is defined as n(3n-1)/2 for n = 1, 2, …, and so on. Therefore, the first few numbers are 1, 5, 12, 22, . . . . Write a method with the following header that returns a pentagonal number: publicstaticintgetPentagonalNumber(int n) For example, getPentagonalNumber(1) returns 1 and getPentagonal- Number(2) returns 5. Write a test program that uses this method to display the first 100 pentagonal numbers with 10 numbers on each line. Use the %7d format to display each number.A regular polygon is an n-sided polygonin which all sides are of the same length and all angles have the same degree (i.e.,the polygon is both equilateral and equiangular). The formula for computing thearea of a regular polygon is given below: Write a method that returns the area of a regular polygon using the following header:public static double area(int n, double side)Write a main method that prompts the user to enter the number of sides and theside of a regular polygon and displays its area. Here is a sample run: Enter the number of sides: 5 ↵EnterEnter the side: 6.5 ↵EnterThe area of the polygon is 72.69017017488385A pentagonal number is defined as n(3n−1) ∕ 2 for n = 1, 2, . . ., etc.. Therefore, the first few numbers are 1, 5, 12, 22, . . . . Write a method with the following header that returns a pentagonal number:public static int getPentagonalNumber(int n) For example, getPentagonalNumber(1) returns 1 and getPentagonalNumber(2) returns 5. In Java, Write a test program that uses this method to display the first 100 pentagonal numbers with 10 numbers on each line. Numbers are separated by exactly one space.
- A pentagonal number is defined as n (3 n-1)/ 2 for n= 1, 2,.. so on. Therefore, the first few numbers are 1, 5, 12, 22, .. Write a method with the following header that returns a pentagonal number: pueIn computational geometry, often you needto find the rightmost lowest point in a set of points. Write the following methodthat returns the rightmost lowest point in a set of points:public static double[]getRightmostLowestPoint(double[][] points)Write a test program that prompts the user to enter the coordinates of six pointsand displays the rightmost lowest point. Here is a sample run: Enter 6 points: 1.5 2.5 −3 4.5 5.6 −7 6.5 −7 8 1 10 2.5 ↵EnterThe rightmost lowest point is (6.5, −7.0)You are building a diving board by placing a bunch of planks of wood end-to-end.There are two types of planks, one of length shorter and one of length longer. You must use exactly K planks of wood. Write a method to generate all possible lengths for the diving board.
- For this problem you will write a method that computes the number of boxes in a pyramid of boxes based on the number of boxes in the base. The boxes in each layer of the pyramid are stacked directly on top of one another (i.e. not offset between two boxes below). For example, below are shown two pyramids, one with base 5 and one with base 6. [] [][] [][][] [][][][] [][][][][] [][][][][][] Implement and test the computePyramidBoxes() method in the PyramidBoxCount class. When testing the computePyramidBoxes() method you should be sure to have at least one test method for each base case and at least one test method for each recursive case in your program.There are several techniques for implementingthe sqrt method in the Math class. One such technique is known as theBabylonian method. It approximates the square root of a number, n, by repeatedlyperforming the calculation using the following formula:nextGuess = (lastGuess + n / lastGuess) / 2When nextGuess and lastGuess are almost identical, nextGuess is theapproximated square root. The initial guess can be any positive value (e.g., 1).This value will be the starting value for lastGuess. If the difference betweennextGuess and lastGuess is less than a very small number, such as 0.0001,you can claim that nextGuess is the approximated square root of n. If not, nextGuessbecomes lastGuess and the approximation process continues. Implementthe following method that returns the square root of n:public static double sqrt(long n)Create a method which will accept a positive integer input and return a value according to the following rules: For multiples of 3 return “Fizz” For multiples of 5 return “Buzz” For multiples of both 3 and 5, return “FizzBuzz” For any other input (valid or otherwise) return a string representation of the input I have this to start: class Solution: def print_fizz_buzz(self, input):# Your code goes here These are the tests: from solution import Solutionimport unittest class SolutionTests(unittest.TestCase): def test1(self):solution = Solution()self.assertEqual(solution.print_fizz_buzz(15), "FizzBuzz") if __name__ == '__main__':unittest.main()
- In this challenge, you need to implement a method which squares passing variables and return their sum. Problem Statement # Implement a method squareSum(double num1, double num2, double num3) in a class SquareSum which takes three numbers, square them and returns their sum. Input: # Three floating point numbers. Output: # Sum of the squares of passing numbers Sample Input # 2, 3, 4 Sample Output # 29Suppose that a Scanner object contains a bunch of tokens all on a single line separated by spaces. For example: 100.5 30.4 pizza 56.8 1000.3 8.2 Also suppose that you have a particular item that you know the price of. Let’s use the following example: Kindle: 99.99 Write a static method: public static double priceIsRight(Scanner s, double price) that takes a Scanner and an item price as parameters and returns the bid that is closest to the item price but not greater than the item price. If all bids are greater than the price, return 0.0. If there are no bids (Scanner is empty) return 0.0. You can assume the Scanner is not null. In the above example. 56.8 should be returned, since it is the number that is closest to 99.99 but not over 99.99. Notice that there may be some invalid tokens in the Scanner's input. The above example has pizza as one of its tokens, which is clearly not a valid bid. Your method should throw these tokens away and not consider them as bids. It is probably…Suppose that a Scanner object contains a bunch of tokens all on a single line separated by spaces. For example: 100.5 30.4 pizza 56.8 1000.3 8.2 Also suppose that you have a particular item that you know the price of. Let’s use the following example: Kindle: 99.99 Write a static method: public static double priceIsRight(Scanner s, double price) that takes a Scanner and an item price as parameters and returns the bid that is closest to the item price but not greater than the item price. If all bids are greater than the price, return 0.0. If there are no bids (Scanner is empty) return 0.0. You can assume the Scanner is not null. In the above example. 56.8 should be returned, since it is the number that is closest to 99.99 but not over 99.99. Notice that there may be some invalid tokens in the Scanner's input. The above example has pizza as one of its tokens, which is clearly not a valid bid. Your method should throw these tokens away and not consider them as bids. It is probably…