Review: Fundamentals of Java
Table of Contents
1.
Session 2 (lab): Review exercises
We advise the students to program according to usual Java conventions. The document Java Coding Guidelines presents a brief introduction to the most important conventions, as well as instructions on how to configure Eclipse according to them.
1.1.
Exercises about arrays
Review arrays with some basic exercises.
Return the biggest integer number of an array of integers.
Return the average of the elements of an array.
Show the elements of an array that are even (divisible by 2).
Show the sumatory of the elements of an array.
1.2.
Displaying a Chess Board in text format on console
Practice for loops.
Implement a program that displays a text based Chess Board on the console (standard output) as follows:
BWBWBWBW
WBWBWBWB
BWBWBWBW
WBWBWBWB
BWBWBWBW
WBWBWBWB
BWBWBWBW
WBWBWBWB
You must implement TWO SOLUTIONS. The first one must use just loops and commands to print on the screen. The second solution must create an array, fill it in with the appropriate values, and finally, display it on the screen.
1.3.
Loop conversion (for -> while)
Practice loops.
1.4.
Conversion of loops (while -> for)
Practice loops.
2.
Homework
2.1.
Check whether a phrase or a word is a palindrome
Review loops.
A palindrome is a word or a phrase that is read the same forwards or backwards. Implement a program that determines whether a given string is a palindrome or not.
2.2.
Calculation of factorial using loops
Practice loops.
Implement a method that returns the factorial of a given number, first using a for loop and then using a while loop.
2.3.
2-dimension arrays
Practice with bi-dimensional arrays.