Answer:
import java.util.Scanner;
class Main {
public static int calcSeries(int n) {
int sum = 0;
for(int i=10; i>=n; i--) {
sum += i;
}
return sum;
}
public static void main(String[] args) {
Scanner reader = new Scanner(System.in);
int n = 0;
do {
System.out.print("Enter n: ");
n = reader.nextInt();
if (n >= 10) {
System.out.println("Please enter a value lower than 10.");
}
} while (n >= 10);
reader.close();
System.out.printf("sum: %d\n", calcSeries(n));
}
}
Answer:
The solution code is written in Python:
- if(distance < 100 or distance > 2000):
- print("The number is not valid")
Explanation:
In this question either one of the two conditions (distance < 100 or distance > 2000) is met, the error message should be generated. Python offers the "or" keyword as a logical operator. The "or" keyword will join two conditions and so long as one of them is True, the final outcome will be evaluated to True. For example, if distance = 90 the error message will be printed. If distance is 2500, the error message will also be printed.
I’m not sure it’s about number of questions, I think it’s based off of rank. Good luck though! I’m happy to answer any questions you have!
Answer:
for(i = 0 ; i < NUM_VALS; ++i)
{
cout << courseGrades[i] << " ";
}
cout << endl;
for(i = NUM_VALS-1 ; i >=0 ; --i)
{
cout << courseGrades[i] << " ";
}
cout << endl;
Explanation:
The first loop initializes i with 0, because we have to print the elements in order in which the appear in the array. We print each element, adding a space (" ") character at its end. After the loop ends, we add a new line using endl.
The second loop will print the values in a reverse order, so we initialize it from NUM_VALS-1, (since NUM_VALS = 4, and array indices are 0,1,2,3). We execute the loop till i >= 0, and we print the space character and new line in a similar way we executed in loop1.