Docsity

Practice Test 1 - Introduction to Computing and Programming | CSCI 1301, Exams of Computer Science

Partial preview of the text

Download Practice Test 1 - Introduction to Computing and Programming | CSCI 1301 and more Exams Computer Science in PDF only on Docsity!

Test 1 CSCI 1301, Spring 2011 Computer Science Department, University of Georgia Administered February 24th, 2011 - 2:00 PM to 3:15 PM

Name:

UGAID:

Questions 1-10 (5pts each): Questions 11-15 (7pts each): Question 16 (15pts):

  1. Explain the procedure necessary to use the Scanner class within a program, then provide example code that creates a Scanner object and reads in a double value from the user. Assume the class and main method are written for you.
  2. Explain the differences between a class variable and a primitive variable. Provide an example of each.
  3. A declared variable that has not been assigned a value will contain. When used within a System.out.println statement, this variable will cause a error.
  1. Explain precedence, then determine the result of the following equation. Would the result be any different without the parentheses?

int temp = ( 19 - 7 ) / ( 2 * ( 9 - 6 ) );

  1. Explain the difference between modular arithmetic ( the mod operator %) and division (/). Provide a code example that determines if an integer is even or odd.
  2. Explain the difference between testing for equality with primitive types vs. class types.
  1. Given the following String, provide a code example that replaces the first letter with ’L’ then capitalizes the entire String.

String temp = “eoud noises”;

  1. Explain the differences between if-else statements and switch statements.
  2. Explain the differences between while loops, do-while loops, and for loops.
  1. What would the following code display?

int a = 5, b = 10, c = 20; String temp = "bell"; temp = temp.toLowerCase();

for( int x = 0; x < 5; x++);{ a++; b += 10; c += 20; System.out.println( (a + b + c + x) + ", " + temp ); }

  1. Write a class for TestExample.java whose main method reads in an integer using the Scanner class. The main method should also print the value’s letter grade equivalent (F:0-59, D:60-69, C:70-79, B: 80-89, A: 90-100). The program should only accept the values 0 through 100 (inclusive), and should not stop if the user enters a number outside of the acceptable range.