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

For this problem please create a new file LabOneProbOne.java and copy/paste the program below into it:

import java.io.*;

public class LabOneProbOne {
	public static void main(String[] args) throws IOException {
	        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		// The code below reads one integer n
		// prompt the user:
		System.out.print("Please enter an integer: ");
		// read a line of input:
		String line = in.readLine();
		// extract the integer from the entered data:
		int n = Integer.parseInt(line);

		// fill in your code here:	
		// print out the value of n
		
		// increment n by 1
		
		// print out the new value of n
		
		System.out.println("Done!");
	}
}

// What happens if the input is not an integer? 

Submit the file to your Wiki lab page.

Problem 2

Each of the following two programs have several compiler errors. Copy/paste the programs into the appropriate java files and get them 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 = " + );
	}
}


public clas LabOneProbThree {
	
	public void main(String[] args) {
		int myVariable = 55;
		myOtherVariable = myVarible + 55;
		double dVariable = myVariable * 2.3 - myOtherVariable / 3.;
		System.out.print("Here is the result: );
		System.out.println(dVariable;
	}
 

Submit both files to your Wiki lab page.

Problem 3

Which of the following are legal variable names in Java? Test each of the names in a program. Write your answers on your Wiki lab page (under the header Lab 1 Problem 3). Submit the program that you used to test these names together with the other files for this lab.
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.