Ex10ArrayWorksheet

# Ex10ArrayWorksheet - Arrays Worksheet Draw the memory...

This preview shows pages 1–3. Sign up to view the full content.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Arrays Worksheet Draw the memory resulting from the following instructions: int myArray; myArray = new int[10]; myArray[0] = 5; myArray[1] = 3; myArray[2] = 2; myArray[3] = 9; myArray[4] = 8; myArray[5] = 6; myArray[6] = 1; myArray[7] = 0; myArray[8] = 4; myArray[9] = 7; int x = 6; What are the values of the following expressions? myArray[5] myArray[x] myArray[x+1] myArray[x]+1 What happens if I write this? myArray[3]++ What will print out? for(int counter = 0; counter < 9; counter++) System.out.printf("%d, ",myArray[counter]-1); Syntactic sugar: Another way to declare, allocate, and initialize an array, if you know how large and what values you want to put in it: int myArray = {5, 3, 2, 9, 8, 6, 1, 0, 4, 7}; /* GradeBreakdown * This example will show a progression of four solutions for * GradeBreakdown, culminating in a very flexible solution that would * not be possible with our first solution. */ import java.util.Scanner; public class GradeBreakdown { public static void main(String args) { Scanner input = new Scanner( System.in ); System.out.println("Welcome to the GradeBook program."); // declare variables double score; int numAs, numBs, numCs, numDs, numFs; // initialize variables numAs = 0; numBs = 0; numCs = 0; numDs = 0; numFs = 0;...
View Full Document

## This note was uploaded on 12/27/2011 for the course CMPSC 5 taught by Professor Franklin during the Fall '09 term at UCSB.

### Page1 / 5

Ex10ArrayWorksheet - Arrays Worksheet Draw the memory...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online