Created
September 1, 2014 10:35
-
-
Save vienhoang/d5bcdab9025d8631c495 to your computer and use it in GitHub Desktop.
Java: 2d array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Main { | |
public static void main(String[] args) { | |
String[][] states = new String[3][2]; | |
states[0][0] = "California"; | |
states[0][1] = "Sacremento"; | |
states[1][0] = "Oregon"; | |
states[1][1] = "Salem"; | |
states[2][0] = "Washington"; | |
states[2][1] = "Olympia"; | |
int st1 = states.length; | |
for (int i = 0; i < st1; i++) { | |
StringBuilder sb = new StringBuilder(); | |
int st2 = states[i].length; | |
for (int j = 0; j < st2; j++) { | |
if (j == 0) { | |
sb.append("The capitol of "); | |
} else { | |
sb.append(" is "); | |
} | |
sb.append(states[i][j]); | |
} | |
System.out.println(sb); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment