Difference between revisions of "CSC212 Lab 3 2014"
(Created page with "--~~~~ ---- __TOC__ <br /> <br /> <br /> <bluebox>This lab presents several problems that deal with arryas, classes, objects, and inheritance. </bluebox> <br /> <br /> =Arrays...") |
(→Arrays) |
||
Line 13: | Line 13: | ||
Takes this simple example program and modify it in the different ways suggested. | Takes this simple example program and modify it in the different ways suggested. | ||
<br /> | <br /> | ||
− | <source lang="java"> | + | :::<source lang="java"> |
public class Lab3_1 { | public class Lab3_1 { | ||
public static void main( String[] args ) { | public static void main( String[] args ) { | ||
Line 27: | Line 27: | ||
# 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 | # 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 | ||
<br /> | <br /> | ||
− | <source lang="java" highlight="1,6"> | + | :::<source lang="java" highlight="1,6"> |
import java.util.Random; | import java.util.Random; | ||
Revision as of 15:00, 10 September 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); } }