Download presentation
Presentation is loading. Please wait.
Published byPrimrose Gaines Modified over 8 years ago
1
2-dimensional Arrays A 2-dimensional array has rows and columns It is actually an “array of arrays” A Tic-Tac-Toe board is an example of a 3 by 3 2-d array Syntax: type[][] name = new type[rows][columns]
2
A loop inside a loop is called a nested loop Almost always, we use nested for-loops to process through a 2-d array Demo2dArray
3
Assignment #1 (Alpha) Create and display a 9-by-16 table. Place the letter k in each “cell.” Display the table. Now, place a randomly-generated lowercase letter in each cell. Display the table again. Hints… –RandomNumberDemo –Ascii
4
Assignment #2 (Classroom) Create a classroom diagram: 5 rows, 6 columns. Place a dash in each cell. There are 12 students in the class. Ask the user where each student wants to sit, and then place an ‘s’ in that spot. After each student is placed, display the classroom. Error checking: –Don’t allow the user to choose a spot that’s already taken. –Prevent OutOfBounds exceptions. AT ALL COSTS.
5
Assignment #3 (Connect3) You know the game Connect 4. Create a version of this game called Connect 3: it uses a 3 by 4 table, and the first player to connect 3 in a row (horizontal, vertical, or diagonal) wins. Remember, it is a 2-player game, and each player chooses a column to drop a piece into. “Gravity” pulls each piece to the lowest spot available. Allow the user to play multiple times if they want to.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.