//demonstrating navigating multidimensional arrays import javax.swing.*; import java.awt.*; import java.awt.event.*; public class StringArray extends JApplet { String id [] [] = { {"Aerofan","45","44","50","92.6%"}, {"ANGEL", "36","46","50","85.9%"}, {"BamBam", "46","45","49","93.3%"}, {"bebe", "45","47","50","92.1%"} }; String name; String grade; public void init () { name = JOptionPane.showInputDialog ( "Enter name" ); } public void paint ( Graphics g ) { for ( int i = 0; i < id.length; i++ ) { if ( name.equals ( id [ i ] [ 0 ] ) ) grade = id [ i ] [ 4 ]; } g.drawString ( "The username " + name + " has a " + grade + " overall", 25, 25 ); g.drawString ( "The whole table looks like: ", 25, 40 ); int y = 60; int x = 50; //the return of the nested for loops! for ( int i = 0; i < id.length; i++ ) { for ( int j = 0; j < id[i].length ; j++ ) { if ( j == 1 ) //I know I'll need more space after x += 60; //the username than anywhere else. else x += 20; g.drawString ( id [ i ] [ j ] , x , y ); } y += 20; //bump the y position by 20 x = 50; //reset the x to 50 for next row } } }