Can you guys plss help me on this problem,..I nid it A.S.A.P.
2.1.Make a program that allows you to create a 3 X 4 integer array. Your program will initialize the array with random numbers from 0 to 1000. Your program also will identify and display the largest value, smallest value, sum and average value of all data in the array.
1
Expert's answer
2012-10-08T11:17:13-0400
import java.util.Random;
public class main {
/** * @param args */ public static void main(String[] args) { int[][] arr=new int[3][4]; Random ran=new Random(); for (int i = 0; i < arr.length; i++) { for (int j = 0; j < arr[0].length; j++)
{ arr[i][j]=ran.nextInt(1001); } }
int max=arr[0][0]; int min=arr[0][0]; int sum=0; int ave; for (int i = 0; i < arr.length; i++) { for (int j = 0; j < arr.length; j++)
{ if(arr[i][j]>max) { max=arr[i][j]; }
if(arr[i][j]<min) { min=arr[i][j]; }
sum+=arr[i][j]; } }
ave=sum/(arr.length*arr[0].length);
System.out.println("largest value "+max); System.out.println("smallest value "+min); System.out.println("sum "+sum); System.out.println("average value "+ave);
Numbers and figures are an essential part of our world, necessary for almost everything we do every day. As important…
APPROVED BY CLIENTS
"assignmentexpert.com" is professional group of people in Math subjects! They did assignments in very high level of mathematical modelling in the best quality. Thanks a lot
Comments
Leave a comment