if(n % 2 == 0){
for(int i = n; i >= 0; i-=2){
System.out.println(i);
}
}
else{
for(int i = n - 1; i >= 0; i-=2){
System.out.println(i);
}
}
Sample output
Output when n = 12
12
10
8
6
4
2
0
Output when n = 21
20
18
16
14
12
10
8
6
4
2
0
Explanation:The above code is written in Java.
The if block checks if n is even by finding the modulus/remainder of n with 2. If the remainder is 0, then n is even. If n is even, then the for loop starts at i = n. At each cycle of the loop, the value of i is reduced by 2 and the value is outputted to the console.
If n is odd, then the else block is executed. In this case, the for loop starts at i = n - 1 which is the next lower even number. At each cycle of the loop, the value of i is reduced by 2 and the value is outputted to the console.
Sample outputs for given values of n have been provided above.
10. This question refers to the chart from the previous question.
Which of the following conclusions is BEST supported by the scatter plot?
OOOO
A. Most dogs breeds have a maximum weight of 100 lbs or more
B. Most dog breeds have a maximum life span of 10 or fewer years
C. All dog breeds that weigh less than 50 pounds have a maximum lifespan of more than 10 years
D. No dog breeds that weigh more than 150 pounds are expected to live more than 10 years.
Answer: C. All dog breeds that weigh less than 50 pounds have a maximum lifespan of more than 10 years.
Explanation:
Looking at the scatter plot, it is shown that all dogs that weigh less than 50 pounds have a maximum lifespan that is above 10 years with a number of them even approaching 20 years.
This means that on average, dogs that weigh less tend to live longer than dogs that weigh more which as shown in the scatter plot have a lower lifespan the heavier they are.
When parameters are passed between the calling code and the called function, formal and actual parameters are matched by: a.
Answer:
their relative positions in the parameter and argument lists.
Explanation:
In Computer programming, a variable can be defined as a placeholder or container for holding a piece of information that can be modified or edited.
Basically, variable stores information which is passed from the location of the method call directly to the method that is called by the program.
For example, they can serve as a model for a function; when used as an input, such as for passing a value to a function and when used as an output, such as for retrieving a value from the same function. Therefore, when you create variables in a function, you can can set the values for their parameters.
A parameter can be defined as a value that must be passed into a function, subroutine or procedure when it is called.
Generally, when parameters are passed between a calling code and the called function, formal and actual parameters are usually matched by their relative positions in the parameter and argument lists.
A formal parameter is simply an identifier declared in a method so as to represent the value that is being passed by a caller into the method.
An actual parameter refers to the actual value that is being passed by a caller into the method i.e the variables or values that are passed while a function is being called.