CSC212 Lab 3 2014
--D. Thiebaut (talk) 16:00, 10 September 2014 (EDT)
Contents
This lab presents several problems that deal with arryas, classes, objects, and inheritance.
Arrays
Takes this simple example program and modify it in the different ways suggested.
public class Lab3_1 {
public static void main( String[] args ) {
int table[] = new int[10];
}
}
- Make your program store numbers in the table using a for-loop. The numbers should be 0, 2, 4, 6, ...18. Make your program display the contents of the array table with a for-loop.
- Make your program store random numbers in the array, and find the largest element, and its index. Using random numbers in Java requires importing a new module into the program, generating a new
import java.util.Random;
public class Lab3_1 {
public static void main( String[] args ) {
int table[] = new int[10];
Random randomGenerator = new Random();
for (int i=0; i<table.length; i++ )
table[i] = randomGenerator.nextInt(100);
}
}