CSE 1310 - Practice Problems - Practice Set 1


Practice Problem 1

File problem1.java contains an incomplete program. The goal of the program is to go through an array of integers, and print out all integers that are greater than or equal to 50.

Complete that program, by defining a print_large function, that satisfies the following specs:

If you implement your function correctly, the program should print:
105
82
60


Practice Problem 2

File problem2.java contains an incomplete program. The goal of the program is similar to that of Problem 1: we want to go through an array of integers, and print out all integers that are greater than or equal to 50. However, here we do it a little bit differently: we do not hardcode the value 50 in the print_large function, but we pass it in as an argument.

Complete that program, by defining a print_large function, that satisfies the following specs:

If you implement your function correctly, the program should print:
105
82
60


Practice Problem 3

File problem3.java contains an incomplete program. The goal of the program is similar to that of Problems 1 and 2: we want to go through an array of integers, and print out all integers that are greater than or equal to 50. However, here we do it in a different way, by writing two functions: keep_large and print_array_list

Define a keep_large function, that satisfies the following specs:

Define a print_array_list function, that satisfies the following specs: If you implement your two functions correctly, the program should print:
105
82
60


Practice Problem 4

File problem4.java contains an incomplete program. The goal of the program is a little different from that of Problems 1, 2, 3. Here the data is stored in an array list, instead of an array. We still want to go through the data in that array list, and print out all integers that are greater than or equal to 50.

You should reuse the print_array_list function from the previous problem.

You should define a new keep_large function, different from your solution in the previous problems, that satisfies the following specs:

If you implement your function correctly, the program should print:
105
82
60


Practice Problem 5

File problem5.java contains an incomplete program. The goal of the program is to read integers stored in a file, and print out all integers that are greater than or equal to 50.

You should reuse the print_array_list and keep_large functions from previous problems.

You should define a new read_numbers function, that satisfies the following specs:

If you implement your function correctly, using file numbers1.txt, the program should print:
105
82
60


Practice Problem 6

Write a function reverse_lines(filename) that:

For example, suppose that, right before calling the function, file file1.txt has these contents:

hello
today is
Tuesday
Then, after calling reverse_lines("file1.txt"), file file1.txt should have these contents:
Tuesday
today is
hello