array as a parameter java code example

Example 1: array as parameter c++

void myFunction(int param[]) {
   .
   .
   .
}

Example 2: java pass array as method parameter

/*
In java, you can create an array like this:
	new int[]{1, 2, 3};
replace `int` with whatever you want
*/

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 3: js array as parameter

function myFunction(a, b, c) {//number of parameters should match number of items in your array
  	//simple use example
  	console.log("a: " + a);
  	console.log("b: " + b);
  	console.log("c: " + c);
}

var myArray = [1, -3, "Hello"];//define your array
myFunction.apply(this, myArray);//call function

Example 4: how to put a string in an array parameter java

public class Test {
  public static void main(String[] args) {
    // Declare a constant value for the number of lockers
    final int NUMBER_OF_LOCKER = 100;

    // Create an array to store the status of each array
    // The first student closed all lockers, each lockers[i] is false
    boolean[] lockers = new boolean[NUMBER_OF_LOCKER];

    // Each student changes the lockers
    for (int j = 1; j <= NUMBER_OF_LOCKER; j++) {
      // Student Sj changes every jth locker
      // starting from the lockers[j - 1].
      for (int i = j - 1; i < NUMBER_OF_LOCKER; i += j) {
        lockers[i] = !lockers[i];
      }
    }

    // Find which one is open
    for (int i = 0; i < NUMBER_OF_LOCKER; i++) {
      if (lockers[i])
        System.out.println("Locker " + (i + 1) + " is open");
    }
  }
}

Example 5: how to take array as an argument in java

import java.util.Scanner;

public class ArraysToMethod {
   public int max(int [] array) {
   }

Example 6: how to declare function with multiple parameter c++

// overloaded function
#include <iostream>
using namespace std;

int operate (int a, int b)
{
  return (a*b);
}

float operate (float a, float b)
{
  return (a/b);
}

int main ()
{
  int x=5,y=2;
  float n=5.0,m=2.0;
  cout << operate (x,y);
  cout << "\n";
  cout << operate (n,m);
  cout << "\n";
  return 0;
}
/*
//Using template->
#include <iostream>

using namespace std;

template<typename Yourname> //U can write class instead of typename

void print (Yourname value)
{
    cout<<value;


}

int main()
{
print<int>(2);	//you can also use-> print(2);
cout<<endl;
print("ali");
}
*/