produce an array from 1 to n java code example

Example 1: create a function that checks the values of the indexes in two arrays and keep a score

const triplets = (arr1,arr2) => {
  let score1 = 0;
  let score2 = 0;
  let resultArr = [0,0]
  for (let i = 0; i < arr1.length; i++){
    if(arr1[i] === arr2[i]) {
      resultArr[0] = score1
      resultArr[1] = score2
    } else if (arr1[i] > arr2[i]) {
      score1++
      resultArr[0] = score1
    } else if (arr1[i] < arr2[i]) {
      score2++
      resultArr[1] = score2
    }
  }
  return resultArr
}

Example 2: Write code to declare an array that will hold calendar months (.e. January to December) java

package array2;

public class Array2 {

    static String months[];
    public static void main(String[] args) {
       months = new String[13];
       months[0] = null ;
       months[1] = "January";
       months[2] = "February";
       months[3] = "March";
       months[4] = "April";
       months[5] = "May";
       months[6] = "June";
       months[7] = "July";
       months[8] = "August";
       months[9] = "September";
       months[10] = "October";
       months[11] = "November";
       months[12] = "December";
       int m = Integer.parseInt( args[0] );
       System.out.println( months[ m ] );
    }
}

Tags:

C Example