1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
kap26 [50]
3 years ago
13

Write a recursive method called printNumPattern() to output the following number pattern.Given a positive integer as input (Ex:

12), subtract another positive integer (Ex: 3) continuallyuntil 0 or a negative value is reached, and then continually add the second integer until therst integer is again reached. For this lab, do not end output with a newline.
Computers and Technology
1 answer:
aleksley [76]3 years ago
6 0

Answer:

Explanation:

The following is written in Java and prints out the pattern to and from the first num parameter that is passed to the function. Meaning it goes from num1 to 0 and then from 0 to num1 again. It prints all of the values in a single line seperated by a space and a test case was used using the values provided in the question. The output can be seen in the attached picture below.

static void printNumPattern(int n1,int n2){

       System.out.print(n1 + " ");

       if(n1<=0) {

           return;

       } else {

           printNumPattern(n1-n2,n2);

       }

       System.out.print(n1 + " ");

   }

You might be interested in
What are the three parts of a camera
son4ous [18]

Answer: Camera lens, Film or sensors, and body.

Explanation: I researched it.

8 0
3 years ago
2. Consider a 2 GHz processor where two important programs, A and B, take one second each to execute. Each program has a CPI of
allsm [11]

Answer:

program A runs in 1 sec in the original processor and 0.88 sec in the new processor.

So, the new processor out-perform the original processor on program A.

Program B runs in 1 sec in the original processor and 1.12 sec in the new processor.

So, the original processor is better then the new processor for program B.

Explanation:

Finding number of instructions in A and B using time taken by the original processor :

The clock speed of the original processor is 2 GHz.

which means each clock takes, 1/clockspeed

= 1 / 2GH = 0.5ns

Now, the CPI for this processor is 1.5 for both programs A and B. therefore each instruction takes 1.5 clock cycles.

Let's say there are n instructions in each program.

therefore time taken to execute n instructions

= n * CPI * cycletime = n * 1.5 * 0.5ns

from the question, each program takes 1 sec to execute in the original processor.

therefore

n * 1.5 * 0.5ns = 1sec

n = 1.3333 * 10^9

So, number of instructions in each program is 1.3333 * 10^9

the new processor :

The cycle time for the new processor is 0.6 ns.

Time taken by program A = time taken to execute n instructions

=  n * CPI * cycletime

= 1.3333 * 10^9 * 1.1 * 0.6ns

= 0.88 sec

Time taken by program B = time taken to execute n instructions

= n * CPI * cycletime

= 1.3333 * 10^9 * 1.4 * 0.6

= 1.12 sec

Now, program A runs in 1 sec in the original processor and 0.88 sec in the new processor.

So, the new processor out-perform the original processor on program A.

Program B runs in 1 sec in the original processor and 1.12 sec in the new processor.

So, the original processor is better then the new processor for program B.

5 0
3 years ago
What are work incidents/situations or ethical problem?<br>​
777dan777 [17]

5 Common Ethical Issues in the Workplace

Unethical Leadership.

Toxic Workplace Culture.

Discrimination and Harassment.

Unrealistic and Conflicting Goals.

Questionable Use of Company Technology.

7 0
3 years ago
Read 2 more answers
To support an internet client, you must have six elements. the first three -- a computer, an operating system and tcp/ip -- are
UkoKoshka [18]
<span>Client software, Internet connection and Internet address</span>
6 0
3 years ago
4.9 Code Practice: Question 4
hichkok12 [17]

total = 0

i = 0

while i < 10:

   temp = float(input("Enter Temperature: "))

   total += temp

   i += 1

print("Sum =", str(total))

I hope this helps!

7 0
3 years ago
Other questions:
  • An advertisement for new headphones lists the cool colors available, the great sound quality, and the fabulous reviews but fails
    14·1 answer
  • Design and implement a class called Sphere that contains instance data that represent the sphere’s diameter. Define the Sphere c
    6·1 answer
  • How prevalent is licensing for software engineers in the United States
    5·1 answer
  • Gina is upgrading your computer with a new processor. She installed the processor into your motherboard and adds the cooling sys
    9·2 answers
  • A 5-stage MIPS pipeline has a register file without forwarding mechanism. How many NOPs (or bubbles) will you need to add to mak
    9·1 answer
  • The federal government is the largest employer of cybersecurity professionals true or false
    5·1 answer
  • 8.10 Code Practice Question 3
    6·1 answer
  • What are the benefits of computer literacy?
    10·1 answer
  • STOP DELETING MY ANSWERS AND QUESTIONS!!!!!!!
    9·1 answer
  • Write a Java program that will be able to generate the sample table below.
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!