SlideShare a Scribd company logo
Hi, Please find my code:
import java.util.Random;
public class ProcessArray {
private int rows; //The attribute for number of rows in matrix
private int columns; //The attribute for number of columns in matrix
private int[][] firstArray; //The attribute for the first array
private int[][] secondArray; //The attribute for the second array
public int[][] getFirstArray() { return firstArray;}
public int[][] getSecondArray() { return secondArray;}
public ProcessArray(int rows, int columns){ //Constructor of object ProcessArray
this.rows = rows;
this.columns = columns;
int[][] array = new int[rows][columns];
initializeArray(array);
randomlyFillArray();
computeArrayValues();
printArray(secondArray);
}
public void initializeArray(int[][] array){ //Initializes first and second arrays and sets each value
to 0
firstArray = new int[rows][columns];
secondArray = new int[rows][columns];
}
public void randomlyFillArray(){ //Fills first array with random numbers
for(int i = 0; i < firstArray.length;i++){
for(int j = 0; j < firstArray[0].length;j++){
Random r = new Random();
int num = r.nextInt(16);
firstArray[i][j] = num;
}
}
}
public void computeArrayValues(){
int col = firstArray[0].length;
int row = firstArray.length;
for(int i = 0; i < row; i++){
for(int j = 0; j< col; j++){
secondArray[i][j] = 0;
if((i - 1) >=0){
secondArray[i][j] += firstArray[i-1][j];
if((j+1) < col)
secondArray[i][j] += firstArray[i-1][j+1];
if(j > 0)
secondArray[i][j] += firstArray[i-1][j-1];
}
if((j+1) < col)
secondArray[i][j] += firstArray[i][j+1];
if(j > 0)
secondArray[i][j] += firstArray[i][j-1];
if((i+1) < row){
secondArray[i][j] += firstArray[i+1][j];
if((j+1) < col)
secondArray[i][j] += firstArray[i+1][j+1];
if(j > 0)
secondArray[i][j] += firstArray[i+1][j-1];
}
}
}
}
public void printArray(int[][] Array){
System.out.println(" Initial Array Filled With Random Numbers:  ");
for(int a = 0; a < firstArray.length; a++){
for(int b = 0; b < firstArray[0].length; b++){
if(b == 0)
System.out.printf("%d ", firstArray[a][b]);
else
System.out.printf("%d ", firstArray[a][b]);
}System.out.println();
}System.out.println();
System.out.println("Computed Array:  ");
for(int a = 0; a < secondArray.length; a++){
for(int b = 0; b < secondArray[0].length; b++){
if(b == 0)
System.out.printf("%d ", secondArray[a][b]);
else
System.out.printf("%d ", secondArray[a][b]);
}
System.out.println();
}System.out.println();
}
public static void main(String[] args) {
ProcessArray pr = new ProcessArray(3, 4);
}
}
/*
Sample Output:
Initial Array Filled With Random Numbers:
7 3 6 12
10 2 11 10
12 14 1 7
Computed Array:
15 36 38 27
38 64 55 37
26 36 44 22
*/
Solution
Hi, Please find my code:
import java.util.Random;
public class ProcessArray {
private int rows; //The attribute for number of rows in matrix
private int columns; //The attribute for number of columns in matrix
private int[][] firstArray; //The attribute for the first array
private int[][] secondArray; //The attribute for the second array
public int[][] getFirstArray() { return firstArray;}
public int[][] getSecondArray() { return secondArray;}
public ProcessArray(int rows, int columns){ //Constructor of object ProcessArray
this.rows = rows;
this.columns = columns;
int[][] array = new int[rows][columns];
initializeArray(array);
randomlyFillArray();
computeArrayValues();
printArray(secondArray);
}
public void initializeArray(int[][] array){ //Initializes first and second arrays and sets each value
to 0
firstArray = new int[rows][columns];
secondArray = new int[rows][columns];
}
public void randomlyFillArray(){ //Fills first array with random numbers
for(int i = 0; i < firstArray.length;i++){
for(int j = 0; j < firstArray[0].length;j++){
Random r = new Random();
int num = r.nextInt(16);
firstArray[i][j] = num;
}
}
}
public void computeArrayValues(){
int col = firstArray[0].length;
int row = firstArray.length;
for(int i = 0; i < row; i++){
for(int j = 0; j< col; j++){
secondArray[i][j] = 0;
if((i - 1) >=0){
secondArray[i][j] += firstArray[i-1][j];
if((j+1) < col)
secondArray[i][j] += firstArray[i-1][j+1];
if(j > 0)
secondArray[i][j] += firstArray[i-1][j-1];
}
if((j+1) < col)
secondArray[i][j] += firstArray[i][j+1];
if(j > 0)
secondArray[i][j] += firstArray[i][j-1];
if((i+1) < row){
secondArray[i][j] += firstArray[i+1][j];
if((j+1) < col)
secondArray[i][j] += firstArray[i+1][j+1];
if(j > 0)
secondArray[i][j] += firstArray[i+1][j-1];
}
}
}
}
public void printArray(int[][] Array){
System.out.println(" Initial Array Filled With Random Numbers:  ");
for(int a = 0; a < firstArray.length; a++){
for(int b = 0; b < firstArray[0].length; b++){
if(b == 0)
System.out.printf("%d ", firstArray[a][b]);
else
System.out.printf("%d ", firstArray[a][b]);
}System.out.println();
}System.out.println();
System.out.println("Computed Array:  ");
for(int a = 0; a < secondArray.length; a++){
for(int b = 0; b < secondArray[0].length; b++){
if(b == 0)
System.out.printf("%d ", secondArray[a][b]);
else
System.out.printf("%d ", secondArray[a][b]);
}
System.out.println();
}System.out.println();
}
public static void main(String[] args) {
ProcessArray pr = new ProcessArray(3, 4);
}
}
/*
Sample Output:
Initial Array Filled With Random Numbers:
7 3 6 12
10 2 11 10
12 14 1 7
Computed Array:
15 36 38 27
38 64 55 37
26 36 44 22
*/

More Related Content

Similar to Hi, Please find my codeimport java.util.Random;public class Pro.pdf

Utility.ppt
Utility.pptUtility.ppt
Utility.ppt
BruceLee275640
 
MagicSquareTest.java import java.util.Scanner;public class Mag.pdf
MagicSquareTest.java import java.util.Scanner;public class Mag.pdfMagicSquareTest.java import java.util.Scanner;public class Mag.pdf
MagicSquareTest.java import java.util.Scanner;public class Mag.pdf
anjanacottonmills
 
import java.util.Scanner;public class ArrayOperation {    inp.pdf
import java.util.Scanner;public class ArrayOperation {     inp.pdfimport java.util.Scanner;public class ArrayOperation {     inp.pdf
import java.util.Scanner;public class ArrayOperation {    inp.pdf
angelsfashion1
 
Lecture 7 arrays
Lecture   7 arraysLecture   7 arrays
Lecture 7 arrays
manish kumar
 
1sequences and sampling. Suppose we went to sample the x-axis from X.pdf
1sequences and sampling. Suppose we went to sample the x-axis from X.pdf1sequences and sampling. Suppose we went to sample the x-axis from X.pdf
1sequences and sampling. Suppose we went to sample the x-axis from X.pdf
rushabhshah600
 
Sharable_Java_Python.pdf
Sharable_Java_Python.pdfSharable_Java_Python.pdf
Sharable_Java_Python.pdf
ICADCMLTPC
 
Refer to my progress on this assignment belowIn this problem you w.pdf
Refer to my progress on this assignment belowIn this problem you w.pdfRefer to my progress on this assignment belowIn this problem you w.pdf
Refer to my progress on this assignment belowIn this problem you w.pdf
arishmarketing21
 
Java programs - bubble sort, iterator, linked list, hash set, reverse string,...
Java programs - bubble sort, iterator, linked list, hash set, reverse string,...Java programs - bubble sort, iterator, linked list, hash set, reverse string,...
Java programs - bubble sort, iterator, linked list, hash set, reverse string,...Sunil Kumar Gunasekaran
 
The Art of Clean Code
The Art of Clean CodeThe Art of Clean Code
The Art of Clean Code
Yael Zaritsky Perez
 
import javautilLinkedList import javautilQueue import .pdf
import javautilLinkedList import javautilQueue import .pdfimport javautilLinkedList import javautilQueue import .pdf
import javautilLinkedList import javautilQueue import .pdf
ADITIEYEWEAR
 
QA Auotmation Java programs,theory
QA Auotmation Java programs,theory QA Auotmation Java programs,theory
QA Auotmation Java programs,theory
archana singh
 
Java binary subtraction
Java binary subtractionJava binary subtraction
Java binary subtraction
Charm Sasi
 
WAP to add two given matrices in Java
WAP to add two given matrices in JavaWAP to add two given matrices in Java
WAP to add two given matrices in Java
One97 Communications Limited
 
1. import java.util.Scanner; public class Alphabetical_Order {.pdf
1. import java.util.Scanner; public class Alphabetical_Order {.pdf1. import java.util.Scanner; public class Alphabetical_Order {.pdf
1. import java.util.Scanner; public class Alphabetical_Order {.pdf
Ankitchhabra28
 
131 Lab slides (all in one)
131 Lab slides (all in one)131 Lab slides (all in one)
131 Lab slides (all in one)
Tak Lee
 
Java Simple Programs
Java Simple ProgramsJava Simple Programs
Java Simple Programs
Upender Upr
 
Chapter13 two-dimensional-array
Chapter13 two-dimensional-arrayChapter13 two-dimensional-array
Chapter13 two-dimensional-arrayDeepak Singh
 
#include stdio.h#include stdlib.h#include string.h#inclu.pdf
#include stdio.h#include stdlib.h#include string.h#inclu.pdf#include stdio.h#include stdlib.h#include string.h#inclu.pdf
#include stdio.h#include stdlib.h#include string.h#inclu.pdf
apleather
 

Similar to Hi, Please find my codeimport java.util.Random;public class Pro.pdf (19)

Utility.ppt
Utility.pptUtility.ppt
Utility.ppt
 
MagicSquareTest.java import java.util.Scanner;public class Mag.pdf
MagicSquareTest.java import java.util.Scanner;public class Mag.pdfMagicSquareTest.java import java.util.Scanner;public class Mag.pdf
MagicSquareTest.java import java.util.Scanner;public class Mag.pdf
 
import java.util.Scanner;public class ArrayOperation {    inp.pdf
import java.util.Scanner;public class ArrayOperation {     inp.pdfimport java.util.Scanner;public class ArrayOperation {     inp.pdf
import java.util.Scanner;public class ArrayOperation {    inp.pdf
 
Lecture 7 arrays
Lecture   7 arraysLecture   7 arrays
Lecture 7 arrays
 
1sequences and sampling. Suppose we went to sample the x-axis from X.pdf
1sequences and sampling. Suppose we went to sample the x-axis from X.pdf1sequences and sampling. Suppose we went to sample the x-axis from X.pdf
1sequences and sampling. Suppose we went to sample the x-axis from X.pdf
 
Sharable_Java_Python.pdf
Sharable_Java_Python.pdfSharable_Java_Python.pdf
Sharable_Java_Python.pdf
 
Refer to my progress on this assignment belowIn this problem you w.pdf
Refer to my progress on this assignment belowIn this problem you w.pdfRefer to my progress on this assignment belowIn this problem you w.pdf
Refer to my progress on this assignment belowIn this problem you w.pdf
 
Java programs - bubble sort, iterator, linked list, hash set, reverse string,...
Java programs - bubble sort, iterator, linked list, hash set, reverse string,...Java programs - bubble sort, iterator, linked list, hash set, reverse string,...
Java programs - bubble sort, iterator, linked list, hash set, reverse string,...
 
The Art of Clean Code
The Art of Clean CodeThe Art of Clean Code
The Art of Clean Code
 
import javautilLinkedList import javautilQueue import .pdf
import javautilLinkedList import javautilQueue import .pdfimport javautilLinkedList import javautilQueue import .pdf
import javautilLinkedList import javautilQueue import .pdf
 
Sam wd programs
Sam wd programsSam wd programs
Sam wd programs
 
QA Auotmation Java programs,theory
QA Auotmation Java programs,theory QA Auotmation Java programs,theory
QA Auotmation Java programs,theory
 
Java binary subtraction
Java binary subtractionJava binary subtraction
Java binary subtraction
 
WAP to add two given matrices in Java
WAP to add two given matrices in JavaWAP to add two given matrices in Java
WAP to add two given matrices in Java
 
1. import java.util.Scanner; public class Alphabetical_Order {.pdf
1. import java.util.Scanner; public class Alphabetical_Order {.pdf1. import java.util.Scanner; public class Alphabetical_Order {.pdf
1. import java.util.Scanner; public class Alphabetical_Order {.pdf
 
131 Lab slides (all in one)
131 Lab slides (all in one)131 Lab slides (all in one)
131 Lab slides (all in one)
 
Java Simple Programs
Java Simple ProgramsJava Simple Programs
Java Simple Programs
 
Chapter13 two-dimensional-array
Chapter13 two-dimensional-arrayChapter13 two-dimensional-array
Chapter13 two-dimensional-array
 
#include stdio.h#include stdlib.h#include string.h#inclu.pdf
#include stdio.h#include stdlib.h#include string.h#inclu.pdf#include stdio.h#include stdlib.h#include string.h#inclu.pdf
#include stdio.h#include stdlib.h#include string.h#inclu.pdf
 

More from anujsharmaanuj14

pH = pKa + log (Sa) where S =moles of salt a = m.pdf
                     pH = pKa + log (Sa) where S =moles of salt a = m.pdf                     pH = pKa + log (Sa) where S =moles of salt a = m.pdf
pH = pKa + log (Sa) where S =moles of salt a = m.pdf
anujsharmaanuj14
 
H is reduced, while Fe is oxidized. Note the oxi.pdf
                     H is reduced, while Fe is oxidized. Note the oxi.pdf                     H is reduced, while Fe is oxidized. Note the oxi.pdf
H is reduced, while Fe is oxidized. Note the oxi.pdf
anujsharmaanuj14
 
Elastic fluids Nonmetals Metals Earths .pdf
                     Elastic fluids  Nonmetals  Metals  Earths        .pdf                     Elastic fluids  Nonmetals  Metals  Earths        .pdf
Elastic fluids Nonmetals Metals Earths .pdf
anujsharmaanuj14
 
Vehicle.javapublic class Vehicle {    Declaring instance var.pdf
Vehicle.javapublic class Vehicle {    Declaring instance var.pdfVehicle.javapublic class Vehicle {    Declaring instance var.pdf
Vehicle.javapublic class Vehicle {    Declaring instance var.pdf
anujsharmaanuj14
 
Ionization energy is the energy required to remove theouter most ele.pdf
Ionization energy is the energy required to remove theouter most ele.pdfIonization energy is the energy required to remove theouter most ele.pdf
Ionization energy is the energy required to remove theouter most ele.pdf
anujsharmaanuj14
 
D. Both C and N are hybridized sp3 .pdf
                     D. Both C and N are hybridized sp3               .pdf                     D. Both C and N are hybridized sp3               .pdf
D. Both C and N are hybridized sp3 .pdf
anujsharmaanuj14
 
The presence of conjugated Carbon-carbon double bonds causes colorat.pdf
The presence of conjugated Carbon-carbon double bonds causes colorat.pdfThe presence of conjugated Carbon-carbon double bonds causes colorat.pdf
The presence of conjugated Carbon-carbon double bonds causes colorat.pdf
anujsharmaanuj14
 
The amount to be deposited at the start of his studies is found as.pdf
The amount to be deposited at the start of his studies is found as.pdfThe amount to be deposited at the start of his studies is found as.pdf
The amount to be deposited at the start of his studies is found as.pdf
anujsharmaanuj14
 
SolutionNet cash provided by operating activities for the year end.pdf
SolutionNet cash provided by operating activities for the year end.pdfSolutionNet cash provided by operating activities for the year end.pdf
SolutionNet cash provided by operating activities for the year end.pdf
anujsharmaanuj14
 
SOA ( Service Oriented Architecture)SOA is a type of architectura.pdf
SOA ( Service Oriented Architecture)SOA is a type of architectura.pdfSOA ( Service Oriented Architecture)SOA is a type of architectura.pdf
SOA ( Service Oriented Architecture)SOA is a type of architectura.pdf
anujsharmaanuj14
 
C. 2nd. .pdf
                     C. 2nd.                                      .pdf                     C. 2nd.                                      .pdf
C. 2nd. .pdf
anujsharmaanuj14
 
pH= -log(1x10-8)= 8SolutionpH= -log(1x10-8)= 8.pdf
pH= -log(1x10-8)= 8SolutionpH= -log(1x10-8)= 8.pdfpH= -log(1x10-8)= 8SolutionpH= -log(1x10-8)= 8.pdf
pH= -log(1x10-8)= 8SolutionpH= -log(1x10-8)= 8.pdf
anujsharmaanuj14
 
P0 = 21.40D1 = 1.07D2 =1.1449D3 = 1.2250P3 = 26.22Growth r.pdf
P0 = 21.40D1 = 1.07D2 =1.1449D3 = 1.2250P3 = 26.22Growth r.pdfP0 = 21.40D1 = 1.07D2 =1.1449D3 = 1.2250P3 = 26.22Growth r.pdf
P0 = 21.40D1 = 1.07D2 =1.1449D3 = 1.2250P3 = 26.22Growth r.pdf
anujsharmaanuj14
 
Nt = No er twhere density at time tNo= = starting densityNr=dN.pdf
Nt = No er twhere density at time tNo= = starting densityNr=dN.pdfNt = No er twhere density at time tNo= = starting densityNr=dN.pdf
Nt = No er twhere density at time tNo= = starting densityNr=dN.pdf
anujsharmaanuj14
 
Normalization is necessay step in creation of database design becaus.pdf
Normalization is necessay step in creation of database design becaus.pdfNormalization is necessay step in creation of database design becaus.pdf
Normalization is necessay step in creation of database design becaus.pdf
anujsharmaanuj14
 
For sound intensity,ratio in dB is given byx = 10log(IIo)We.pdf
For sound intensity,ratio in dB is given byx = 10log(IIo)We.pdfFor sound intensity,ratio in dB is given byx = 10log(IIo)We.pdf
For sound intensity,ratio in dB is given byx = 10log(IIo)We.pdf
anujsharmaanuj14
 
Exp- Listeria monocytogenes is a facultative anaerobic bacteria tha.pdf
Exp- Listeria monocytogenes is a facultative anaerobic bacteria tha.pdfExp- Listeria monocytogenes is a facultative anaerobic bacteria tha.pdf
Exp- Listeria monocytogenes is a facultative anaerobic bacteria tha.pdf
anujsharmaanuj14
 
DNA controversy is a dispute about whether Rosalind Franklin and Wil.pdf
DNA controversy is a dispute about whether Rosalind Franklin and Wil.pdfDNA controversy is a dispute about whether Rosalind Franklin and Wil.pdf
DNA controversy is a dispute about whether Rosalind Franklin and Wil.pdf
anujsharmaanuj14
 
Delta is a measures of the change in price of an option for a one po.pdf
Delta is a measures of the change in price of an option for a one po.pdfDelta is a measures of the change in price of an option for a one po.pdf
Delta is a measures of the change in price of an option for a one po.pdf
anujsharmaanuj14
 
consider the cross between White petals and dark blue petalsFlower.pdf
consider the cross between White petals and dark blue petalsFlower.pdfconsider the cross between White petals and dark blue petalsFlower.pdf
consider the cross between White petals and dark blue petalsFlower.pdf
anujsharmaanuj14
 

More from anujsharmaanuj14 (20)

pH = pKa + log (Sa) where S =moles of salt a = m.pdf
                     pH = pKa + log (Sa) where S =moles of salt a = m.pdf                     pH = pKa + log (Sa) where S =moles of salt a = m.pdf
pH = pKa + log (Sa) where S =moles of salt a = m.pdf
 
H is reduced, while Fe is oxidized. Note the oxi.pdf
                     H is reduced, while Fe is oxidized. Note the oxi.pdf                     H is reduced, while Fe is oxidized. Note the oxi.pdf
H is reduced, while Fe is oxidized. Note the oxi.pdf
 
Elastic fluids Nonmetals Metals Earths .pdf
                     Elastic fluids  Nonmetals  Metals  Earths        .pdf                     Elastic fluids  Nonmetals  Metals  Earths        .pdf
Elastic fluids Nonmetals Metals Earths .pdf
 
Vehicle.javapublic class Vehicle {    Declaring instance var.pdf
Vehicle.javapublic class Vehicle {    Declaring instance var.pdfVehicle.javapublic class Vehicle {    Declaring instance var.pdf
Vehicle.javapublic class Vehicle {    Declaring instance var.pdf
 
Ionization energy is the energy required to remove theouter most ele.pdf
Ionization energy is the energy required to remove theouter most ele.pdfIonization energy is the energy required to remove theouter most ele.pdf
Ionization energy is the energy required to remove theouter most ele.pdf
 
D. Both C and N are hybridized sp3 .pdf
                     D. Both C and N are hybridized sp3               .pdf                     D. Both C and N are hybridized sp3               .pdf
D. Both C and N are hybridized sp3 .pdf
 
The presence of conjugated Carbon-carbon double bonds causes colorat.pdf
The presence of conjugated Carbon-carbon double bonds causes colorat.pdfThe presence of conjugated Carbon-carbon double bonds causes colorat.pdf
The presence of conjugated Carbon-carbon double bonds causes colorat.pdf
 
The amount to be deposited at the start of his studies is found as.pdf
The amount to be deposited at the start of his studies is found as.pdfThe amount to be deposited at the start of his studies is found as.pdf
The amount to be deposited at the start of his studies is found as.pdf
 
SolutionNet cash provided by operating activities for the year end.pdf
SolutionNet cash provided by operating activities for the year end.pdfSolutionNet cash provided by operating activities for the year end.pdf
SolutionNet cash provided by operating activities for the year end.pdf
 
SOA ( Service Oriented Architecture)SOA is a type of architectura.pdf
SOA ( Service Oriented Architecture)SOA is a type of architectura.pdfSOA ( Service Oriented Architecture)SOA is a type of architectura.pdf
SOA ( Service Oriented Architecture)SOA is a type of architectura.pdf
 
C. 2nd. .pdf
                     C. 2nd.                                      .pdf                     C. 2nd.                                      .pdf
C. 2nd. .pdf
 
pH= -log(1x10-8)= 8SolutionpH= -log(1x10-8)= 8.pdf
pH= -log(1x10-8)= 8SolutionpH= -log(1x10-8)= 8.pdfpH= -log(1x10-8)= 8SolutionpH= -log(1x10-8)= 8.pdf
pH= -log(1x10-8)= 8SolutionpH= -log(1x10-8)= 8.pdf
 
P0 = 21.40D1 = 1.07D2 =1.1449D3 = 1.2250P3 = 26.22Growth r.pdf
P0 = 21.40D1 = 1.07D2 =1.1449D3 = 1.2250P3 = 26.22Growth r.pdfP0 = 21.40D1 = 1.07D2 =1.1449D3 = 1.2250P3 = 26.22Growth r.pdf
P0 = 21.40D1 = 1.07D2 =1.1449D3 = 1.2250P3 = 26.22Growth r.pdf
 
Nt = No er twhere density at time tNo= = starting densityNr=dN.pdf
Nt = No er twhere density at time tNo= = starting densityNr=dN.pdfNt = No er twhere density at time tNo= = starting densityNr=dN.pdf
Nt = No er twhere density at time tNo= = starting densityNr=dN.pdf
 
Normalization is necessay step in creation of database design becaus.pdf
Normalization is necessay step in creation of database design becaus.pdfNormalization is necessay step in creation of database design becaus.pdf
Normalization is necessay step in creation of database design becaus.pdf
 
For sound intensity,ratio in dB is given byx = 10log(IIo)We.pdf
For sound intensity,ratio in dB is given byx = 10log(IIo)We.pdfFor sound intensity,ratio in dB is given byx = 10log(IIo)We.pdf
For sound intensity,ratio in dB is given byx = 10log(IIo)We.pdf
 
Exp- Listeria monocytogenes is a facultative anaerobic bacteria tha.pdf
Exp- Listeria monocytogenes is a facultative anaerobic bacteria tha.pdfExp- Listeria monocytogenes is a facultative anaerobic bacteria tha.pdf
Exp- Listeria monocytogenes is a facultative anaerobic bacteria tha.pdf
 
DNA controversy is a dispute about whether Rosalind Franklin and Wil.pdf
DNA controversy is a dispute about whether Rosalind Franklin and Wil.pdfDNA controversy is a dispute about whether Rosalind Franklin and Wil.pdf
DNA controversy is a dispute about whether Rosalind Franklin and Wil.pdf
 
Delta is a measures of the change in price of an option for a one po.pdf
Delta is a measures of the change in price of an option for a one po.pdfDelta is a measures of the change in price of an option for a one po.pdf
Delta is a measures of the change in price of an option for a one po.pdf
 
consider the cross between White petals and dark blue petalsFlower.pdf
consider the cross between White petals and dark blue petalsFlower.pdfconsider the cross between White petals and dark blue petalsFlower.pdf
consider the cross between White petals and dark blue petalsFlower.pdf
 

Recently uploaded

Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Atul Kumar Singh
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
EduSkills OECD
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
Peter Windle
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
DhatriParmar
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Po-Chuan Chen
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
Peter Windle
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 

Recently uploaded (20)

Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 

Hi, Please find my codeimport java.util.Random;public class Pro.pdf

  • 1. Hi, Please find my code: import java.util.Random; public class ProcessArray { private int rows; //The attribute for number of rows in matrix private int columns; //The attribute for number of columns in matrix private int[][] firstArray; //The attribute for the first array private int[][] secondArray; //The attribute for the second array public int[][] getFirstArray() { return firstArray;} public int[][] getSecondArray() { return secondArray;} public ProcessArray(int rows, int columns){ //Constructor of object ProcessArray this.rows = rows; this.columns = columns; int[][] array = new int[rows][columns]; initializeArray(array); randomlyFillArray(); computeArrayValues(); printArray(secondArray); } public void initializeArray(int[][] array){ //Initializes first and second arrays and sets each value to 0 firstArray = new int[rows][columns]; secondArray = new int[rows][columns]; } public void randomlyFillArray(){ //Fills first array with random numbers for(int i = 0; i < firstArray.length;i++){ for(int j = 0; j < firstArray[0].length;j++){ Random r = new Random(); int num = r.nextInt(16); firstArray[i][j] = num; } } } public void computeArrayValues(){ int col = firstArray[0].length; int row = firstArray.length;
  • 2. for(int i = 0; i < row; i++){ for(int j = 0; j< col; j++){ secondArray[i][j] = 0; if((i - 1) >=0){ secondArray[i][j] += firstArray[i-1][j]; if((j+1) < col) secondArray[i][j] += firstArray[i-1][j+1]; if(j > 0) secondArray[i][j] += firstArray[i-1][j-1]; } if((j+1) < col) secondArray[i][j] += firstArray[i][j+1]; if(j > 0) secondArray[i][j] += firstArray[i][j-1]; if((i+1) < row){ secondArray[i][j] += firstArray[i+1][j]; if((j+1) < col) secondArray[i][j] += firstArray[i+1][j+1]; if(j > 0) secondArray[i][j] += firstArray[i+1][j-1]; } } } } public void printArray(int[][] Array){ System.out.println(" Initial Array Filled With Random Numbers: "); for(int a = 0; a < firstArray.length; a++){ for(int b = 0; b < firstArray[0].length; b++){ if(b == 0) System.out.printf("%d ", firstArray[a][b]); else System.out.printf("%d ", firstArray[a][b]); }System.out.println(); }System.out.println(); System.out.println("Computed Array: ");
  • 3. for(int a = 0; a < secondArray.length; a++){ for(int b = 0; b < secondArray[0].length; b++){ if(b == 0) System.out.printf("%d ", secondArray[a][b]); else System.out.printf("%d ", secondArray[a][b]); } System.out.println(); }System.out.println(); } public static void main(String[] args) { ProcessArray pr = new ProcessArray(3, 4); } } /* Sample Output: Initial Array Filled With Random Numbers: 7 3 6 12 10 2 11 10 12 14 1 7 Computed Array: 15 36 38 27 38 64 55 37 26 36 44 22 */ Solution Hi, Please find my code: import java.util.Random; public class ProcessArray { private int rows; //The attribute for number of rows in matrix private int columns; //The attribute for number of columns in matrix private int[][] firstArray; //The attribute for the first array private int[][] secondArray; //The attribute for the second array
  • 4. public int[][] getFirstArray() { return firstArray;} public int[][] getSecondArray() { return secondArray;} public ProcessArray(int rows, int columns){ //Constructor of object ProcessArray this.rows = rows; this.columns = columns; int[][] array = new int[rows][columns]; initializeArray(array); randomlyFillArray(); computeArrayValues(); printArray(secondArray); } public void initializeArray(int[][] array){ //Initializes first and second arrays and sets each value to 0 firstArray = new int[rows][columns]; secondArray = new int[rows][columns]; } public void randomlyFillArray(){ //Fills first array with random numbers for(int i = 0; i < firstArray.length;i++){ for(int j = 0; j < firstArray[0].length;j++){ Random r = new Random(); int num = r.nextInt(16); firstArray[i][j] = num; } } } public void computeArrayValues(){ int col = firstArray[0].length; int row = firstArray.length; for(int i = 0; i < row; i++){ for(int j = 0; j< col; j++){ secondArray[i][j] = 0; if((i - 1) >=0){ secondArray[i][j] += firstArray[i-1][j]; if((j+1) < col) secondArray[i][j] += firstArray[i-1][j+1]; if(j > 0)
  • 5. secondArray[i][j] += firstArray[i-1][j-1]; } if((j+1) < col) secondArray[i][j] += firstArray[i][j+1]; if(j > 0) secondArray[i][j] += firstArray[i][j-1]; if((i+1) < row){ secondArray[i][j] += firstArray[i+1][j]; if((j+1) < col) secondArray[i][j] += firstArray[i+1][j+1]; if(j > 0) secondArray[i][j] += firstArray[i+1][j-1]; } } } } public void printArray(int[][] Array){ System.out.println(" Initial Array Filled With Random Numbers: "); for(int a = 0; a < firstArray.length; a++){ for(int b = 0; b < firstArray[0].length; b++){ if(b == 0) System.out.printf("%d ", firstArray[a][b]); else System.out.printf("%d ", firstArray[a][b]); }System.out.println(); }System.out.println(); System.out.println("Computed Array: "); for(int a = 0; a < secondArray.length; a++){ for(int b = 0; b < secondArray[0].length; b++){ if(b == 0) System.out.printf("%d ", secondArray[a][b]); else System.out.printf("%d ", secondArray[a][b]); } System.out.println();
  • 6. }System.out.println(); } public static void main(String[] args) { ProcessArray pr = new ProcessArray(3, 4); } } /* Sample Output: Initial Array Filled With Random Numbers: 7 3 6 12 10 2 11 10 12 14 1 7 Computed Array: 15 36 38 27 38 64 55 37 26 36 44 22 */