Question
1.Write a method named printTriangle that uses for loops to produce the following output: # ## ### #### ##### ###### Type your Java solution code
1.Write a method named printTriangle that uses for loops to produce the following output:
# ## ### #### ##### ######
Type your Java solution code here:
2. The following console program is redundant. Rewrite it to use variables and expressions so that calculations are not repeated.
public class Receipt extends ConsoleProgram { public void run() { // Compute total owed, assuming 8% tax and 15% tip println("Subtotal: " + (38 + 40 + 30)); println("Tax: " + (38 + 40 + 30) * .08); println("Tip: " + (38 + 40 + 30) * .15); println("Total: " + (38 + 40 + 30 + (38 + 40 + 30) * .08 + (38 + 40 + 30) * .15)); } }
Type your Java solution code here:
3. Write a console program in a class named Fibonacci that displays all the numbers in the Fibonacci Sequence up to a given max, starting with 0. The Italian mathematician Leonardo Fibonacci devised the Fibonacci sequence as a way to model the growth of a population of rabbits. The first two terms in the sequence are 0 and 1, and every subsequent term is a sum of the previous two terms. (The Fibonacci sequence has numerous applications in computer science and shows up in surprising places. It's used to compute logarithms, index and retrieve data, and as a building block in some route-planning algorithms.) Output from one example run:
This program lists the Fibonacci sequence. 0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181 6765
This program should continue as long as the value of the term is less than the maximum value. To do this, you should use a while loop, presumably with a header line that looks like this:
while (term < MAX_TERM_VALUE)
Note that the maximum term value is specified using a named constant.
Type your Java solution code here:
4. Write nested for loops to produce the following output:
....1 ...22 ..333 .4444 55555
Type your Java solution code here:
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started