CamolaZ

Aulas iniciais de LPOO

Apr 30th, 2016
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.20 KB | None | 0 0
  1. class BreakWithLabelDemo {
  2.     public static void main(String[] args) {
  3.  
  4.         int[][] arrayOfInts = {
  5.             { 32, 87, 3, 589 },
  6.             { 12, 1076, 2000, 8 },
  7.             { 622, 127, 77, 955 }
  8.         };
  9.         int searchfor = 12; // pesquisa por este numero e não pelo tamanho do vetor...
  10.  
  11.         int i;
  12.         int j = 0;
  13.         boolean foundIt = false;
  14.  
  15.     search:
  16.         for (i = 0; i < arrayOfInts.length; i++) {
  17.             for (j = 0; j < arrayOfInts[i].length;
  18.                  j++) {
  19.                 if (arrayOfInts[i][j] == searchfor) {
  20.                     foundIt = true;
  21.                     break search;
  22.                 }
  23.             }
  24.         }
  25.  
  26.         if (foundIt) {
  27.             System.out.println("Found " + searchfor + " at " + i + ", " + j);
  28.         } else {
  29.             System.out.println(searchfor + " not in the array");
  30.         }
  31.        
  32.         String[] names = { "d", "e", "f" };
  33.         for (int h = 0; h < names.length; h++)
  34.             System.out.println(names[h] );
  35.             System.out.print( "tamanho: " + names.length + '\n');
  36.         String[] name = { "Z", "x", "y" };
  37.         for (String nam: name)
  38.         System.out.println(nam);
  39.     }
  40. }
Add Comment
Please, Sign In to add comment