CS 1713 Sample Exam 1

1. _ Write a declaration to declare a variable to represent each of the following.
Choose the data type and identifier name appropriately.
1. the number of students in a class
2. the average grade for an exam
3. the name of a student
4. a UTSA ID
5. a constant representing the maximum size of a class

2. _ Write a code segment that sets the variable sideUp to a random integer between 1 and 6.

3. _ Suppose we have:
```   int x = 11;
int y = 5;
double z = 13.0;
double w = 4.0;
```
Evaluate each of the following expressions:
1. x/y
2. x/w
3. (x + z)/y
4. (x * w)/y
5. x % y
6. x/(y-1)+z/(y-1)

4. _ Write a code segment that prints a message indicating whether the String variables s1 and s2 are the same.

5. _ Coffee beans are \$8 a pound, but there is a 10% discount on the total order if you buy more than 5 pounds.
Write a code segment that sets the price based on the number of pounds.
Assume that the price and pounds can each have a fractional part.

6. _ Write a code segment that print the message:
The value is in range
if the value of total is between 7 and 23, inclusive.
Otherwise, it does nothing.

7. _ Write a code segment that prompts the user for an integer and then prints a message if the value entered was greater than 10.

8. _ Use a do-while to write a code segment that keeps prompting the user for an integer until the value is greater than 10.
It then prints the last value entered.

9. _ Write a code segment that prints the longer of the two strings name1 and name2. Print them both if they have the same length.

10. _ Write a code segment that declares sum and sets it to the sum of the squares of the first 100 positive integers. (Start with 1.)

11. _ Write a code segment that declares average and sets it to the average of the squares of the first 100 positive integers. (Start with 1.)

12. _ Write a method that takes an array of integers as a parameter and returns the sum of the array elements.

13. _ Write a method that takes an array of integers as a parameter and returns the maximum value stored in the array. Return 0 if the array has no elements.