JAVA Practice Exercises
JAVA Practice Exercises
𝑛𝑛 2𝜋𝑛
𝑛! ≈
𝑒𝑛
Practice Exercise 2
Write a JAVA Program that requests from the user to input a certain number of
seconds and then would determine and output the equivalent number of hours,
minutes and remaining seconds.
Practice Exercise 3
Design and implement a JAVA program called UnitAverage.java that reads 2
integers from the user and prints the average of their unit numbers (i.e., their digits).
For example, if the user enters 65 and 94, your program must print the average of
their unit numbers (5 and 4 respectively) which is 4.5.
Practice Exercise 4
Write a JAVA program, called Fractions.java, that asks the user to enter two fractions in the format
of: numerator / denominator. Your program should then add the two fractions and display the answer
as a simplified fraction. To achieve this, the program needs to indicate to the user the need to enter a
fraction as such: the numerator followed by a white space then /, then another white space, and finally
the denominator. An example of an entered fraction is 2 / 3. Observe that this is not taken as a
String object but as a stream of entered integers separated by non-integer characters. The two
fractions must be entered in this way.
2) To simplify a fraction, both the numerator and denominator need to be divided by their Greatest
Common Divisor (GCD). Intuitively, one way to compute the GCD of two numbers say a and b, check the
divisibility of both these numbers in a loop that exhaustively scans all numbers in the range 1 to the
minimum of a and b and make sure to record the biggest number that divides both of them. This latter is,
thus, the GCD of the two numbers a and b.