©1994-2003 Kevin Boone
Home     Section index     K-Zone home Simple Java programs

Site search

Glossary
Confused by computer jargon? Look it up!

Shameless plug


Now available!

Articles
- Ten-minute guide to setting up a WAP site

- Talk like your boss: new developments in managerese

More...

Development
File handling in the Linux kernel

Java development for the Sony-Ericsson P800

SunONE Application Server 7 FAQ

More...

Linux
Using Linux with the Treo 600

- Linux on the Tecra M1

- Some notes on openzaurus

More...

Download
Java stuff

Linux stuff

More...

(Please read the download policy)

Home automation
The X10 system

Linux TW723 driver

More...

The K-Zone
K-Zone computing

K-Zone law

K-Zone education and science

K-Zone motorcycles

K-Zone DIY

K-Zone railways

K-Zone martial arts

About the author

K-Zone home page

 
Software development
Computing
Hello1.java
Add1.java
Add1_1.java
AwtTest.java
Button1.java
Button2.java
Calculator.java
CalculatorApp.java
ClockApplet.java
CountSpace1.java
DateTime.java
Div1.java
DoNothing.java
Factorial1.java
Factorial2.java
FontChooser.java
IfTest.java
Inheritance1.java
Loan.java
DiceThrower.java
Queue.java
Reverse1.java
SoundApplet.java
Stressometer.java
TextReaderTest.java
WebMerge.java
Zener.java
`MultiplicationTable' example program: displays multiplication tables; demonstrates loop operations

MultiplicationTable.java

// MultiplicationTable.java

// A program that displays a multiplication table in the form:
//  1 x 7 = 7
//  2 x 7 = 14
//  3 x 7 = 21
//   etc.
 
// The table to be displayed is stored in the constant `tableNumber'

// Kevin Boone, May 1999

import java.applet.Applet;
import java.awt.*;

public class MultiplicationTable extends Applet
{
/// QUESTION: what does `final' mean here? Does it make any difference if the 
///  word `final' is removed?
final int tableNumber = 12;

/// QUESTION: what does the operation `paint' do?
public void paint (Graphics g)
	{
	/// QUESTION: for what values of `i' does this `for' loop execute?
	for (int i = 1; i <= 12; i++)
		{
		int result = i * tableNumber;	
		String displayString = Integer.toString(12) 
			+ " x " + Integer.toString(i) 
			+ " = " + Integer.toString(result);

		/// QUESTION: what do the two `20's in this line do?
		g.drawString (displayString, 20, i * 20);
		}

	}
}