CSci 2101 Problem set 1. Java conditionals, loops.

Due Thursday, May 26th at 11:59pm (by e-mail)

30 points

The problem set is individual. You may discuss it in general terms, but don't look at each other's code. Significant help from others must be acknowledged.

Problem 1 (8 points)

Write a program that declares three integers (n1, n2, and n3) and then print them in order (the smallest one first). Make sure that your program works for all possible initial orderings. Assume that all three integers are different. Write down in comments what data you used to test your program.

Problem 2 (7 points)

Write a program that prints a string backward in a loop.

Problem 3 (7 points)

Write a program to find the number of occurrences of a given substring in a string. Use indexOf method in a loop (what is the return value of indexOf when the substring is not found?). Print the result only once, after the loop. Show your test data.

Problem 4 (8 points)

Write a program that simulates a roll of a six-sided die and repeats the rolls (in a loop) until the sum of the results exceeds 20. The program must print out all the results of rolls and the running sum.

How to submit

Submit your Java file(s) to me by e-mail. The subject must be Problem Set N, where N is the problem set number.

CSci 2101 course web site.

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.