Exercises

Below are a list of exercises to complete. Answers will be provided in the next section.

Important

To learn properly it is recommended to attempt the exercises before looking at the answers.

Hint

All programs except the challenge will only require System.out.println(); or System.out.print();.

  1. Write a program that will display the following in the output console:

Hello World!
It is very nice to meet you.
This is one of my first Java programs.
  1. Write a program that will display the following in the output console:

RRRRR    OOO    BBBBB    OOO   TTTTT
 R  R   O   O   B   B   O   O    T
 RRRR  O     O  BBBB   O     O   T
 R  R   O   O   B   B   O   O    T
RR   R   OOO    BBBBB    OOO     T
  1. Write a program that will create a table like this:

x     x^2      x^3      x^4
1     1        1        1
2     4        8        16
3     9        27       81
4     16       64       256
5     25       125      625
  1. Write a program that will display the result of:

    \[1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9\]
  2. Write a program that will disapply the result of:

    \[\begin{equation} \frac{10.6 * 4.0 - 3.2 * 1.0}{20.6 - 1.8} \end{equation}\]
  3. Write a program that converts 30°C to Fahrenheit

Hint

The formula is \(\begin{equation}\frac{9}{5}*C+32\end{equation}\)

Challenge Question

Note

Challenge questions are here to stump you and test your problem solving skills. The content in a challenge question will be covered in later units.

  1. Add onto question 6 by having the user input a value in Celsius to be converted.

Example the user inputted 30°C

Enter the temperature to convert in °C: 30
30°C is equal to 86°F

Note

A user might input a value such as 30.5