1 Write a method that is passed an array as a parameter The

1) Write a method that is passed an array as a parameter. The method should set all of the values in this array to 7.2. The method should return the size of the array.

2)Write a method that prints all the values in a 2-dimensional array that it receives as a parameter. Assume that the array is an array of integers.

Solution

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

/**
*
* @author Surya
*/
public class ArrayM {
  
    //@SuppressWarnings(\"empty-statement\")
  
    int oneD(double a[])
    {
        int l =a.length;
        int i;
        for(i=0;i<l;i++)
        {
            a[i]=7.2;//setting all values to 7.2
        }
      
        return l;
    }
    void TwoDprint(int b[][])
    {
        int i,j,l=b.length;
      
        for(i=0;i<l;i++)
        {
            for(j=0;j<l;j++)
            {
                System.out.print(b[i][j]+\" \");//priting 2d array elements..
            }
            System.out.println();
        }
      
      
    }
    public static void main(String argv[])
    {
        ArrayM n = new ArrayM();
        double a[]=new double[10];
        int b[][] = new int[3][3];
        int i,j;
        for(i=0;i<3;i++)
        {
            for(j=0;j<3;j++)
            {
                b[i][j]=i+j;
            }
        }
      
        n.oneD(a);
        n.TwoDprint(b);
      
      
      
      
      
    }
  
}

1) Write a method that is passed an array as a parameter. The method should set all of the values in this array to 7.2. The method should return the size of the
1) Write a method that is passed an array as a parameter. The method should set all of the values in this array to 7.2. The method should return the size of the

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site