Explored using 2D arrays
This commit is contained in:
parent
5bf00ee959
commit
c340aaf216
2 changed files with 25 additions and 0 deletions
BIN
out/production/java_practice/Numpad.class
Normal file
BIN
out/production/java_practice/Numpad.class
Normal file
Binary file not shown.
25
practice_projects/src/Numpad.java
Normal file
25
practice_projects/src/Numpad.java
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
public class Numpad {
|
||||
|
||||
public static void main(String[] args){
|
||||
// This project is to show how to use 2D Arrays
|
||||
// a.k.a. Nested arrays (an array of arrays)
|
||||
|
||||
// 2D arrays are useful for storing a matrix of data.
|
||||
|
||||
|
||||
// Remember - Characters are single quotes 'C'
|
||||
char[][] numpad = {{'1', '2', '3'},
|
||||
{'4', '5', '6'},
|
||||
{'7', '8', '9'},
|
||||
{'*', '0', '#'}};
|
||||
|
||||
// We need nested loops to print columns and rows
|
||||
for(char[] row : numpad){
|
||||
for(char number : row){
|
||||
System.out.print(number + " ");
|
||||
}
|
||||
// Between every row add an empty line
|
||||
System.out.println();
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue