## CSci 2101 Data Structures: Lab 1

Before you start, please read A very brief introduction to Linux. Please ignore the description of scp.

Tasks marked with * are extra credit. Work on these tasks only if you are not pressed for time.

### Problem 1

Copy/paste program 1 from this page into a new file Test.java (create the file using jEdit). Compile and run the program.
• Change the message that the program prints to any other message. Recompile the program and run it again. Comment out the new line of code.
``````
System.out.println("Welcome to\njava world!");
``````
right after the commented-out line. Recompile and run the program. What will be printed by the program? Write your answer on the Wiki page. Comment out the new line.
• Add the following two lines of code right after the commented-out line:
``````
int n = 6;
System.out.println("n = " + n);
``````
What gets printed? What happens if you change 6 in the first line to 5? Write the answer on the Wiki page.
• Add the following line right after the line `int n = 5;`
``````
int m = 7;
``````
Change the program so that it prints
``````
n = 5, m = 7
``````
• Change the values of n and m to 3 and 4, respectively. Do not change anything else in the program. If you did the previous step correctly, your program should print
``````
n = 3, m = 4
``````
If it doesn't, think of how you can fix the program.
• Submit the program to your Wiki page.

### Problem 2

Copy/paste program 2 from this page into a new file Variables.java. Study the program carefully.
• What do you think will be printed by the last two print statements? Write your guess on a piece of paper. If you can think of several possible answers, write them all down. Run the program. Were the answers among those that you have predicted? Write your answer on the Wiki page.
• Do you think you understand how the division operator / works on integer variables? Can you predict what will be the result of 6/5? 1/2? -3/2? Test your answers. Write down the results of your experiment and your conclusions on the Wiki page. Submit the program with your last test case.

### Problem 3 Extra credit

The program below has several compiler errors. Copy/paste the program into the appropriate java file and try to fix the errors and get the program to compile and run.
``````
public class LabOneProbTwo {
public static void main(String[] args) {
Int x = 5.0
double y = 2.4;

y = x + 3.3;
System.println("x = " + x + " y = " + );
}
}
``````

This is a lab from CSci 2101 course.

The views and opinions expressed in this page are strictly those of the page author. The contents of this page have not been reviewed or approved by the University of Minnesota.