Array Example

This is a simple program which declares, initializes and assigns values to an array.

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

public class FindBig extends Applet
{

int[]numbers;
int biggest;
public void init()

{

numbers = new int[5];
biggest = 0;
numbers[0] = 4;
numbers[1] = 7;
numbers[2] = 31;
numbers[3] = 12;
numbers[4] = 3;

}
public void paint(Graphics g)
{

biggest = numbers[0];
for (int i = 1; i<5; i++)

{

if (numbers[i] > biggest) biggest = numbers[i];

}
g.drawString(Integer.toString(biggest)+ " is the biggest number", 100, 100);
}

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License