Java Examples

Convert Inches to Centimetres

Java, Swing 14.10.2011 No Comments
Convert Inches to Centimetres

The next example was kindly shared by one of our members. She had a Java Swing assignment to create a Swing GUI for converting Inches to Centimetres and had no idea where to start. We helped her break down the problem and come up with a solution. The resulting code can be found below.

Read More

Counting numbers

The assignment here is to read a text file containing a list of numbers. We need to report how many numbers were in the file, the sum of all the numbers, the average of all numbers, and the minimum and maximum number. First step is to read the file and for this we can use…

Read More

Check Palindromes using Recursion

Java 1.6.2011 No Comments

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…

Read More

High Low Guessing Game

Java 17.5.2011 5 Comments

The assignment here is to write a simple game where the user tries to guess a randomly selected number. After each guess the application tells the user if the guess is too high or too low. This is repeated until the user finally guesses the number. First thing we need is to generate a random…

Read More

Month Calendar

Java 1.5.2011 No Comments
Month Calendar

The following application shows how to format displaying a month in a way that would be suitable for including in a calendar. This involves making sure days of the week are all vertically aligned, and that the first day of the week appears in the first column. The day that is considered the first day…

Read More
s2Member®