Advertisement
HarrJ

B8 Day 11 multi level arr with for loops

Sep 22nd, 2022 (edited)
905
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.51 KB | None | 0 0
  1. package mattroseb8wk2;
  2.  
  3. // paano kung for loop ang gagamitin
  4. public class Day11B {
  5.     public static void main(String[] args) {
  6.         String[][] list1 = new String[5][2];
  7.         list1[0][0] = "Cake";
  8.         list1[0][1] = "Sweet";
  9.         list1[1][0] = "Sampaloc";
  10.         list1[1][1] = "Sour";
  11.         list1[2][0] = "Kape";
  12.         list1[2][1] = "Bitter";
  13.         list1[3][0] = "Bagoong";
  14.         list1[3][1] = "Salty";
  15.         list1[4][0] = "Bicol Express";
  16.         list1[4][1] = "Spicy";
  17.        
  18.         // pwede yung rows lang ang i for loop mo
  19.         for (int i = 0; i < list1.length; i++) {
  20.             System.out.println(list1[i][0] + " tastes "
  21.                     + list1[i][1] + "!");
  22.         }
  23.        
  24.         // i loop mo pati yung columns
  25.         for (int j = 0; j < list1.length; j++) {
  26.             for (int k = 0; k < list1[j].length; k++) {
  27.                 System.out.print(list1[j][k] + " | ");
  28.             }
  29.             System.out.println();
  30.         }
  31.         // yung i/j para malaman anong row ka na?
  32.         // yung k para malaman anong column ka na!!
  33.  
  34. //------------------------------------------------------------------
  35.  
  36.         String[][] listNames = {
  37.             {"ALVARO","SUNSHINE","ORDAS"}
  38.             ,{"CALLEJA","JUSTIN","BENITEZ"}
  39.             ,{"DIMAFILIS","ARIANE DAPHNE MARIE","GUNTANG"}
  40.             ,{"DINGLE","JUSTINE","ALVARO"}
  41.             ,{"FUENTES","JAHLELLEA","EBORA"}
  42.             ,{"GADON","ELLYN","RELOX"}
  43.             ,{"GALERO","BENGIE"}
  44.             ,{"GUILLERMO","ELDRICH JONELLE","HALOG"}
  45.             ,{"LEIDO","LEAH","MASIBAY"}
  46.             ,{"LUTAP","RINCE POWELL","BERMUDEZ"}
  47.             ,{"MANGAMPO","EMERLITO","MARARANG"}
  48.             ,{"MARIGMEN","MARIO","MAMUNGAY","JR."}
  49.             ,{"ROSETE","MARGIE","BARBOSA"}
  50.             ,{"SANIDAD ","TRISHA NICOLE","HONTILANO"}
  51.             ,{"VALERO","SANDRA JEAN ","TIVIDAD"}
  52.             ,{"VELAR","EMILY","PADILLA"}
  53.             ,{"VILLANUEVA","DANIELLE","TORRES"}
  54.             ,{"SISON","CHEZTER JOHN","HONTILANO"}
  55.             ,{"VALERO","NIKKO","DELA CRUZ"}
  56.             ,{"LUISON","ROSELYN SENICA","S"}
  57.         };
  58.        
  59.         for (String[] listN : listNames) {
  60.             System.out.println(listN[1] + " " + listN[0]);
  61.         }
  62.        
  63.         System.out.println("----------------------");
  64.         for (String[] listN : listNames) {
  65.             for (String name : listN) {
  66.                 System.out.print(name + " | ");
  67.             }
  68.             System.out.println();
  69.         }
  70.  
  71.  
  72.     }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement