Problems, Programming, Process & Linux

  1. What are the 2 parts of a formal problem description?
  2. Give an example of a formal problem description.
  3. What is pseudo-code?
  4. What is an algorithm?
  5. Why are algorithms written in pseudo-code?
  6. Write pseudo-code for the MAXIMUM problem.
  7. What is an imperative language?
  8. What is the syntax of a language?
  9. What is a plain-text file?
  10. What are the 4 steps in the typical compilation process? Explain each.
  11. Java is not typical. Explain its compilation process. Use the word byte-code in your explanation.
  1. What type of architecture do modern computers use? Explain the basic components.
  2. Why is a computer considered a state machine?
  1. What is the name of the website that provides answers to thousands of programming questions?
  2. When searching for oracle documentation on the Internet, what 2 words should you include in your search to ensure you get the correct documentation?
  1. What is SSH? What is it used for?
  2. What are the Linux commands that perform the following tasks.
    1. Print the current working directory?
    2. Display the manual page for the ls command?
    3. Suppose the current working directory is /home/batman. Using an absolute path change directory to /etc.
    4. Suppose the current working directory is /home/batman. Using an relative path change directory to /etc.
    5. List the contents of the current working directory so that you can see the file and directory permissions.
    6. Clear the screen.
    7. Make a directory named csci-105 in the current working directory.
    8. Suppose csci-105 is a directory in the current working directory. Rename csci-105 to csci105.
    9. Suppose csci105 is a directory in the current working directory and suppose it is empty. Remove the directory named csci105.
    10. Suppose csci105 is a directory in the current working directory and suppose it is not empty. Remove the directory named csci105.
    11. Create an empty file in the current working directory named hello.c.
    12. Suppose hello.c is in the current working directory. Copy the contents of the file hello.c to standard out.
    13. Suppose hello.c is in the current working directory. Rename hello.c to jello.c.
    14. Suppose hello.c is in the current working directory /home/batman. Move the file to /home/batman/csci105.
    15. Suppose hello.c is in the current working directory. Delete the file.

Data Representation, Types & Variables

  1. At the most basic level, what values are stored in memory, transmitted on the bus and manipulated in the CPU?
  2. Count from 1 to 10 in binary.
  3. How many distinct values can be stored using n bytes?
  4. Convert the following numbers to base 2: 3010, 20310, 74810, 1023
  5. What is a bit?
  6. What is a byte?
  7. What is ASCII?
  8. What is Unicode?
  9. How is the character ‘A’ stored in computer memory?
  1. What are the two modes in vi and how do you change from one to another?
  2. How do you save a file in vi?
  3. What command do you enter on the command line to submit the problem hello to Kattis assuming you are using Java, your main() function is in the class Hello and your only source code file is Hello.java.
  1. What are the two ways to write comments in Java?
  2. What is a variable?
  3. How is a variable declared?
  4. What are the 8 primitive types?
  5. Which primitive type(s) store whole numbers?
  6. Which primitive type(s) store characters?
  7. Which primitive type(s) store decimal values?
  8. Which primitive type(s) store Boolean values?
  9. What are the differences between the types that store whole numbers?
  10. What are the differences between the types that store decimal numbers?
  11. What is an identifier?
  12. What are the rules for naming identifiers?
  13. What is a literal?
  14. How do you initialize a variable?
  15. Declare a variable named height that stores a whole number and initialize it to hold the value 70.
  16. Declare a variable named initial that stores a character and initialize it to hold the character X.
  17. Declare a variable named response that stores a Boolean value and initialize it to hold the value false.
  18. Declare a variable named area that stores a decimal number and initialize it to hold the value 3.705.
  19. Declare a variable named title that stores a string of characters and initialize it to hold the value Papillion.
  20. What are the names of the two streams that are automatically available to Java programmers? Describe what these streams are used for.
  21. Write a statement that prints “I am 70 inches tall” using the variable height defined above.
  22. Write a statement that prints “My middle initial is X” using the variable initial defined above.
  23. Write a statement that prints “The respondent answered false” using the variable response defined above.
  24. Write a statement that prints “The area of the circle is 3.7 sq. ft.” using the variable area defined above.
  25. Write a statement that prints “Have you read the book Papillion?” using the variable title defined above?
  26. Write a complete block of code that reads an integer from the keyboard and stores the value in a variable named age.

Assignment & Conditional Statements

  1. Declare a variable named numMinutes that holds a 32 bit whole number.
  2. Declare a variable named numSeconds that holds a 64 bit whole number
  3. Write code that creates a variable named ratio that has a value equivalent to the sine of 35 radians.
  4. Write code that creates a variable named length that has a value equivalent to the square root of 22.
  5. Write code that creates a variable name finished that holds the Boolean value true.
  1. Suppose two integers named maxAge and curAge are declared and have been initialized. Write a statement that creates a variable named process and using the ? operator, sets the value of process to true if curAge is not equal to maxAge, otherwise sets the value of process to false.
  2. Suppose a variable named average has been declared and initialized to some decimal value. Write a block of code that sets a Boolean variable named pass to true if average is greater than 65, otherwise sets pass to false.
  3. Suppose a variable named letterGrade has been declared and initialized to one of the characters A, B, C, D, or F. Write a block of code that sets a variable named points to a value dependent on the value of letterGrade according to the following table.

letterGrade points
A 5
B 4
C 3
D 2
F 0

  1. Suppose two variables named score1 and score2 hold decimal values. Write a block of code that uses a nested if statements to set the value of a third variable named result according to the following table.

result condition
score1 score1 is positive and score1 is greater than score2
score2 score1 is positive and score2 is greater or equal to score1
0 score1 is negative


Scope, Precedence & While-loops

  1. Determine if the following code fragments breaks scope rules.
int x = 0;
if (x == 3)
    int y = 1;
y = 2;
int x = 0;
while(x < 10) {
    int y = 0;
    if (y < 10)
        y++;
    y = 5;
    x++;
}
int x = 0;
while (x < 10) {
    if (x == 2)
        int y = 4;
    if (x == 3)
        int y = 5;
    x++;
}
  1. List the precedence of the following operators.

(), =, ++, --, |, *, /, %, &, +, -, ==, !=, >, <, >=, <=

  1. Write a while loop that prints the numbers between 1 and 100, each on a new line.
  2. Write a while loop that sums the numbers 2, 4, 6, 8, …, 100.
  3. Write a while loop that counts the number of integers between 1 and 100 that are divisible by 3.
  4. Write a fragment of code that has an infinite-loop. Within the loop, the program asks the user to enter an integer then reads in the integer.   If the value of the number read is 0, the program exits the loop, otherwise the program continues in the loop.
  5. Write a while loop that adds the first k numbers of the Fibonacci sequence: {1, 1, 2, 3, 5, 8, 13, 21, …}.