CSci 2101 Lab 1. Java variables, data types.

Due Tuesday, May 25th at 11:59pm (by e-mail)

25 points

The lab may be done in pairs or individually.

Setup

Lab questions

When you are answering these questions, feel free to delete some of the program code or comment out unnecessary print statements.

  1. Add a statement to multiply two integer (i.e. int) variables, print out the result.
  2. Add a statement to divide two integers, store the result in a variable, and print that variable. What happens when the two numbers cannot be evenly divided? Write a comment in your program to explain the results.
  3. Print out the value of n. Then write
    n = n + 3;
    
    Print out its value again. Briefly explain (in comments) what happens.
  4. What does n++; do? Briefly explain (in comments).
  5. Based on the four printouts with a a comment "implicit type conversions" explain what happens when division works on a mix of integer and double numbers.
  6. Change the comparison x < 5 to x <= 5, verify that it works as expected.
  7. What happens if you compare characters 'a' and 'b' using <?
  8. Make two deliberate errors in the program that cause it to fail compilation. What changes did you make? What were the error messages? Were they understandable?
  9. Come up with two "what if" questions (for instance: what if I assign a double to an int? What if I declare two variables with the same name?). Write down your questions, your tests, and your answers.

How to submit

Submit the FirstJava.java file and the answer to all the questions that require explanations. The answers may be in comments in the program file or in a separate file or directly in your e-mail message. The subject of the message must be 2101 Lab 1. Make sure to CC your group partner if you worked with another person.


CSci 2101 course web site.