
Concept explainers
Java program
In main method:
- Create 2-D Array, called m:
- the row size of array m is 15
- ask user to input column size of array m
- fill all array elements as double numbers in the range of (7.0, 17.0) by using random object
- create 2-d array, called double [][]md = {{1,1,1},{2,0,1},{4,7,4}};
- pass the above array m and md to call the following two methods
- MaxCol(m);
- MaxCol(md);
- System.out.println (“the average of array m is: ” + returnLast3RowAvg(m));
- System.out.println (“the average of array md is: ” + returnLast3RowAvg(md));
- Print out the largest column sum, and the average of the last 3 rows of array m and md.
In MaxCol(double[][]array) method, find and print the largest column sum in the array.
In returnLast3RowAvg(double[][]array) method, find the average of the elements in the last 3 rows in the array and return this average value.

import java.util.Scanner;
public class MyArrayTest {
public static void main(String[] args) {
//declaring 2D array
double m[][]=new double[15][];
Scanner sc=new Scanner(System.in);
//asking user for input
System.out.print("Enter Column size of array : ");
int n=sc.nextInt();
//populate m array by random values
for(int i=0;i<15;i++) {
m[i]=new double[n];
for(int j=0;j<n;j++) {
m[i][j]=(Math.random() * ((17.0 - 7.0) + 1)) + 7.0;
}
}
//create 2D array
double [][]md={{1,1,1},{2,0,1},{4,7,4}};
//calling methods and print result
MaxCol(m);
MaxCol(md);
System.out.println("Average of Last three Row element Array m : "+returnLast3RowAvg(m));
System.out.println("Average of Last three Row element Array md : "+returnLast3RowAvg(md));
}
public static void MaxCol(double [][]array) {
//creating variable to hold max value
double max=0;
//iterating from column by row order
for(int j=0;j<array[0].length;j++) {
double sum=0;
for(int i=0;i<array.length;i++)
//find sum
sum=sum+array[i][j];
//check for sum is greater than max
if(max<sum)
max=sum;
}
//print result
System.out.println("Largest Column sum is : "+max);
}
public static double returnLast3RowAvg(double[][]array) {
//creating variable to hold sum value
double sum=0;
int k=0;
//this loop will run for three rows only
for(int i=array.length-3;i<array.length;i++) {
for(int j=0;j<array[i].length;j++) {
//find sum
sum=sum+array[i][j];
k++;
}
}
//return average
return sum/k;
}
}
Trending nowThis is a popular solution!
Step by stepSolved in 3 steps with 3 images

- How is this code written in java?arrow_forwardPrompt: In Python language, write a function that applies the logistic sigmoid function to all elements of a NumPy array. Code: import numpy as np import math import matplotlib.pyplot as plt import pandas as pd def sigmoid(inputArray): modifiedArray = np.zeros(len(inputArray)) #YOUR CODE HERE: return(modifiedArray) def test(): inputs = np.arange(-100, 100, 0.5) outputs = sigmoid(inputs) plt.figure(1) plt.plot(inputs) plt.title('Input') plt.xlabel('Index') plt.ylabel('Value') plt.show() plt.figure(2) plt.plot(outputs,'Black') plt.title('Output') plt.xlabel('Index') plt.ylabel('Value') plt.show() test()arrow_forwardJava Netbeansarrow_forward
- We have an array variable ‘var’ int var[4] = {25,20,30,40}; Find the memory address of the first element of in the array: var[0]arrow_forwardPython Please **Bold is code** Recap of two-dimensional arrays and their numpy implementation import numpy as np my_2d_array = np.array([[1,2],[3,4],[5,6]]) print("This is my_2d_array:") print(my_2d_array) print("This array has shape " + str(my_2d_array.shape) + " as there are " + str(my_2d_array.shape[0]) + " rows and " + str(my_2d_array.shape[1]) + " columns.") print("The entry of the array with row index " + str(1) + " and column index " + str(1) + " has value " + str(my_2d_array[1,1])) 1) In this problem, implement a TwoDArray class that is meant to mimic (some of) the functionality of a two-dimensional numpy array. DO NOT use numpy at any point. 1A) Give the class an __init__ method Make sure that the variable array is a valid input. This means you should a) Make sure that array is a list of lists. and b) Make sure that each of the inner lists has the same length. You do not need to check for anything else. Rise the appropriate error(s) if these conditions are not met. It is up…arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education





