Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

2d array java

char[][] array = new int[rows][columns];
Comment

writing values in 2d array java


public class Sample {
    public static void main(String[] args) {

        String names[][] = {
                { "jasmine", "jasmine123" },
                { "lyka", "lyka123" },
                { "marbie", "marbie123" }
        };
        names[1][0] = "lyka panget";
        System.out.println(names[1][0]);
    }
}
Comment

2d array java

 int[][] arr = new int[10][20]; 
        arr[0][0] = 1; 
Comment

define 2d array in java

const testMatrix = [
  [1, 1, 1, 0, 0],
  [1, 1, 1, 0, 1],
  [0, 1, 0, 0, 1],
  [0, 0, 0, 1, 1]
];

const directions = [
  [-1, 0], //up
  [0, 1], //right
  [1, 0], //down
  [0, -1] //left
]

const numberOfIslands = function(matrix) {
  if(matrix.length === 0) return 0;
  let islandCount = 0;

  for(let row = 0; row < matrix.length; row++) {
    for(let col = 0; col < matrix[0].length; col++) {
      if(matrix[row][col] === 1) {
        islandCount++;
        matrix[row][col] = 0;
        const queue = [];
        queue.push([row, col]);

        while(queue.length) {
          const currentPos = queue.shift();
          const currentRow = currentPos[0];
          const currentCol = currentPos[1];

          for(let i = 0; i < directions.length; i++) {
            const currentDir = directions[i];
            const nextRow = currentRow + currentDir[0];
            const nextCol = currentCol + currentDir[1];

            if(nextRow < 0 || nextRow >= matrix.length || nextCol < 0 || nextCol >= matrix[0].length) continue;

            if(matrix[nextRow][nextCol] === 1) {
              queue.push([nextRow, nextCol]);
              matrix[nextRow][nextCol] = 0;
            }
          }
        }
      }
    }
  }

  return islandCount;
}
Comment

PREVIOUS NEXT
Code Example
Java :: java jbutton trigger action 
Java :: jersey get session time 
Java :: java class extension 
Java :: validate data type in request body spring validation 
Java :: Convert Java File to Kotlin File 
Java :: first method in jdbc 
Java :: ex: Overflow in java 
Java :: Execute method on load 
Java :: confirmation dialog android 
Java :: a multi-value map, Map<K, Collection<V, supporting multiple values per key 
Java :: how to sort a interable in java 
Java :: test spring cloud stream 
Java :: Uri/Beecrowd problem no - 1150 solution in Java 
Java :: how to create an abstract class in java 
Java :: jLabel copy 
Java :: Sling authentication handler example 
Java :: capitalize in controlP5 
Java :: java escribir ventana grafica 
Java :: android studio clear child views 
Java :: maximise the rides with the given tokens java 
Java :: java division int by 0 
Java :: lighting strike solved 
Java :: newinstance in java giving exception 
Java :: component spring 
Java :: java optional parameters 
Java :: java lambda 
Java :: sorting algorithms in java 
Java :: java compare char 
Java :: @runwith junit 5 
Java :: Android java toArray to String array 
ADD CONTENT
Topic
Content
Source link
Name
2+6 =