Archive for the ‘Java’ Category

Palindromes

13.4.2011 1 Comment

A popular problem is how to determine if a String is a Palindrome or not, the following will also assume we are only dealing with Palindromes of single words ie. no spaces or punctuation. The way to determine this is to compare the characters on the left and right ends of the String. If they…

Money Change Breakdown What is the smallest number of coins (or notes) that are required to give a specified amount of change? This is the next problem we will address. To solve this problem we use basically the same process a shop keeper would when giving change to customers. That is we look for the largest denomination coin/note…

Pascals Triangle

Write a Java application that prints the first 10 lines of Pascals Triangle. Each row of a Pascals Triangle can be calculated from the previous row so the core of the solution is a method that calculates a row based on the previous row which is passed as input. Once we have that it is…

Prime numbers

The assignment here is to calculate all prime numbers less than 100. The solution provided uses the following to determine if a given number is prime. 2 is prime Any number divisible by 2 is not prime If the number is divisible by any odd number then it is not prime Otherwise it is prime…

Pythagoras Theorem

One of our member students was asked to implement the Pythagoras Theorem using Java. This is a good opportunity to introduce the Math class which contains a collection of static methods for various mathematical functions. We need the square root method (sort) to calculate the hypotenuse, and can also use the pow() method to calculate…

Fibonnaci Number

Generating Fibonacci numbers is an assignment often given to Java students when they are being introduced to recursion. Recursion is programming technique that involves a method calling itself to solve a problem. When implementing a recursive solution we look for two things: A base case that returns a value without any subsequent recursive calls. A…

This problem involves understanding some of the basics of building a Swing application including how individual components are laid out inside a window, and how your application can react to the user interacting with the application. In this case we need to update a text field whenever a button is pressed. The key points to…

Simple Mortgage Calculator 