Skip to content

Latest commit

 

History

History
34 lines (26 loc) · 1.76 KB

java-basics.md

File metadata and controls

34 lines (26 loc) · 1.76 KB

Exercises – Java Basics

You should be able to complete these after doing some of a basic Java tutorial, such as this one. The problems increase in complexity, so a little extra research will go a long way if you're stuck.

1. If you haven't already, write a 'Hello, world!' program in Java.
2. Write a program to print every number from 0 to 100.

After that, modify your program to print every even number from 0 to 100. For a more advanced task, try the FizzBuzz challenge:

Write a program that prints the numbers from 1 to 100, but for multiples of three print “Fizz” instead of the number and for the multiples of five print “Buzz”. For numbers which are multiples of both three and five print “FizzBuzz”.

Example output is:

...
Buzz
11
Fizz
13
14
FizzBuzz
...
3. Write a method to sum all of the numbers in an array.

You could also write others to subtract, multiply, and divide. After that, modify the function so it takes a String or Char argument: '+', '-', '*', or '/'. Throw an exception if it isn't one of those characters.

Helpful Links: Exceptions in Java

4. Numbers and Letters

Write a program that, given an integer, returns an English string representation, e.g. 1 -> 'one', '15' -> fifteen, '27' -> twenty seven. This should work for all numbers up to 1000.

As an extension exercise, your solution for this could be used to solve Project Euler problem 17.

Helpful Links: