Write a complete program named Test2.java with a method named printPattern and the main method. The...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Write a complete program named Test2.java with a method named printPattern and the main method. The printPattern method displays a pattern of n/2 rows of ascending even numbers up to n. n should be passed to the method as a parameter. You can assume that n is an even number. public static void printPattern (int n) The main method that calls print Pattern is given below: } public static void main(String[] args) { // Create a Scanner Scanner input = new Scanner(System.in); // Prompt the user to enter the number of lines System.out.print ("Enter an even number between 2 to 20: "); int patternTarget = input.nextInt(); printPattern (patternTarget); Here are three sample outputs when the program is executed: Enter an even number between 2 to 20: 10 2 24 246 2468 2 4 6 8 10 Enter an even number between 2 to 20: 2 2 Enter an even number between 2 to 20: 20 2 24 246 2468 2 4 6 8 10 2 4 6 8 10 12 2 4 6 8 10 12 14 2 4 6 8 10 12 14 16 2 4 6 8 10 12 14 16 18 2 4 6 8 10 12 14 16 18 20 1 Write a complete program named Test2.java with a method named printPattern and the main method. The printPattern method displays a pattern of n/2 rows of ascending even numbers up to n. n should be passed to the method as a parameter. You can assume that n is an even number. public static void printPattern (int n) The main method that calls print Pattern is given below: } public static void main(String[] args) { // Create a Scanner Scanner input = new Scanner(System.in); // Prompt the user to enter the number of lines System.out.print ("Enter an even number between 2 to 20: "); int patternTarget = input.nextInt(); printPattern (patternTarget); Here are three sample outputs when the program is executed: Enter an even number between 2 to 20: 10 2 24 246 2468 2 4 6 8 10 Enter an even number between 2 to 20: 2 2 Enter an even number between 2 to 20: 20 2 24 246 2468 2 4 6 8 10 2 4 6 8 10 12 2 4 6 8 10 12 14 2 4 6 8 10 12 14 16 2 4 6 8 10 12 14 16 18 2 4 6 8 10 12 14 16 18 20 1
Expert Answer:
Answer rating: 100% (QA)
Heres the complete program Test2java that implements the printPattern method and th... View the full answer
Related Book For
Introduction To Programming With Java A Problem Solving Approach
ISBN: 9781260575248
3rd International Edition
Authors: John Dean
Posted Date:
Students also viewed these programming questions
-
Project Goals In this project, you will be developing a simple Java application (texttool) using an agile, test-driven process involving multiple deliverables. While you will receive one grade for...
-
4 Comparative Programming Languages illustrating your answer by explaining the meaning of the following fragment of code: [self isAwake] whileTrue: [| item | item := self askForCookie. (self...
-
After numerous campus interviews, Greg Thorpe, a senior at Great Northern College, received two office interview invitations from the Baltimore offices of two large firms. Both firms offered to cover...
-
(a) Calculate the percent ionization of 0.0075 Mbutanoic acid (ka = 1.5 x 10. (b) Calculate the percent ionization of 0.0075 M butanoic acid in a solution containing 0.085 M sodium butanoate.
-
Find the values of k for which kx 2 - 4x + 8 = 0 has two distinct roots.
-
Describe various principles identified in the medical code of ethics.
-
According to the trade press, the success record of knowledge management systems has been spotty. Why do you think this is? What steps must organizations take to give their knowledge management...
-
(a) How many ways can three balls of different colors - yellow, red, and green - be put in a ball can? (b) How many different one-to-one correspondences are there between the two sets {1,2,3} and...
-
4. Construct models for both R-2-chlorobutane and its enantiomer S-2-chlorobutane. For each of the types of structures shown, fill in the necessary atoms to draw both stereoisomeers. Wedge Newman...
-
A false positive indicates: a. higher probability of a material misstatement. b. further testing is required. c. an item was incorrectly identified as notable. d. an item was correctly identified as...
-
Compare and contrast the following pairs of concepts: - Climate mitigation and climate adaptation policies. - Climate debt and climate reparations. - The transfer of emissions reduction units (ERUs)...
-
The following represent key considerations in accessing data except: a. understanding the data available. b. the size of the dataset. c. obtaining read-only access. d. determining the accuracy of the...
-
How can an ADA assist with the risk assessment during an audit?
-
Which of the following is a data error? a. missing data b. duplicate data c. incorrect data d. all of the above
-
One should always be wary of using unit costs for decision-making, because unit costs: a. can be multiplied by a different number of units, suggesting that the cost data is scalable. b. ignore...
-
During the year land was revalued and the surplus reported as Revaluation surplus; and an asset costing 80,000, written down to 38,000, was sold for 40,000. Identify the cost of any non-current...
-
The distribution of the energy of the molecules is also of importance in the kinetics of chemical reactions. The fraction of molecules with energy in the range between \(E\) and \(E+d E\) is given...
-
Show the details leading to the equation (1.52) in the text, \[D_{\mathrm{AA}}=\frac{1}{3} \bar{c} \lambda\] where \(D_{\mathrm{AA}}\) is the self-diffusion coefficient.
-
The simple formula \(C_{p}=(5 / 2) R\) (molar units) is valid only for monatomic gases. A simple extension that has been suggested is \[C_{p}=\left(5+N_{\mathrm{r}} ight) \frac{1}{2} R\] where...
Study smarter with the SolutionInn App