Advertisement
mrScarlett

2D Array

Oct 9th, 2016
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1.  
  2. public class TwoD
  3. {
  4. public static void main(String[] args){
  5. int studentsMarks [][];//declare 2d array
  6. studentsMarks=new int [3][3];//3 students 3 marks
  7.  
  8. //access first cell
  9. studentsMarks[0][0]=22;
  10. studentsMarks[2][1]=44;//student 3 subject 2
  11. studentsMarks[1][2]=17;//student 2 subject 3
  12.  
  13. for (int x=0; x<3; x++){
  14. for (int y=0; y<3; y++){
  15. System.out.print(studentsMarks[x][y]+" | ");
  16. }
  17. System.out.println("");
  18. }
  19. }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement