using arrays as parameters java code example
Example 1: java pass array as method parameter
public static void doSomething(int[] list) {
System.out.println("Something is done.");
}
public static void main(String[] args) {
doSomething(new int[]{1, 2, 3});
}
Example 2: how to put a string in an array parameter java
public class Test {
public static void main(String[] args) {
final int NUMBER_OF_LOCKER = 100;
boolean[] lockers = new boolean[NUMBER_OF_LOCKER];
for (int j = 1; j <= NUMBER_OF_LOCKER; j++) {
for (int i = j - 1; i < NUMBER_OF_LOCKER; i += j) {
lockers[i] = !lockers[i];
}
}
for (int i = 0; i < NUMBER_OF_LOCKER; i++) {
if (lockers[i])
System.out.println("Locker " + (i + 1) + " is open");
}
}
}
Example 3: passing array to function java
public int min(int [] array) {
int min = array[0];
for(int i = 0; i<array.length; i++ ) {
if(array[i]<min) {
min = array[i];
}
}
return min;
}
int minimum = min(myArray)