CS 1713 Introduction to Computer Science, Spring 2008 Quiz 1 Comments
21 people took this quiz. Eight people got 1 point and 2 people got 2 points.
A program segment is not a method.
It does not have a name and it does not return anything.
It does not have to declare or create the variables mentioned in the problem
    (unless it explicitly says to declare them).
It should only do what the problem states and no more.
It should not print anyting unless you are explictly told to do so.
-
Write a program segment that sets the boolean variable found
to true if the integer variable num is between 1 and 100, inclusive.
- In Java, there is no single symbol for less than or equal.
- Many people confused && and ||
- Do not change found if the condition is not satisfied.
if ( (num >=1) && (num <= 100))
found = true;
-
Write a program segment that uses a loop to set the integer variable
sum to the
sum of the squares of the integers between 1 and 1000, inclusive.
- A for loop is best for this.
- sum needs to be initialized (but you do not need to declare it).
- The loop index needs to be declared.
- square and square root are different.
sum = 0;
for (int i=1; i<=1000; i++)
sum = sum + i*i;