Question

In: Computer Science

1. Implement a public method named initialize. It takes a twodimensional square array of integers...

1. Implement a public method named initialize. It takes a two dimensional square array of integers named

array as a parameter. It initializes all of the elements of the array to the sum of their indices except for the
major diagonal (upper left to lower right) where each element is initialized to -1. (For testing use a 4X4 or
5X5 array and have the application print out the array in 2 dimension format.

2. Implement a method named totals that takes a two dimensional integer array named array as a parameter
and returns a one dimensional array where each element is the sum of the columns of the input array.

3. A method named vowels that accepts a String array named alpha. The method will return the index of the

String that contains the most vowels. If there is a tie anyone will be good.

4. A method named count that accepts 2 parameters, an array of integers named array and an integer named min. The method will return the number of elements that are greater than ‘min’.

5. A method named order that accepts an integer array named digits. The method will print to the screen the both the maximum and minimum values of the array.

6. A method named summit that accepts 2 integer arrays named gamma and delta. If the arrays are the same size the method will return an array of the sum of the corresponding elements. If they are of different sizes the method will return an array of 10 elements where all of the elements are set to -1.

7. A method named border that accepts a two dimensional array of chars named array as a parameter. It initializes all of the elements of the array to ‘x’ except for the perimeter (first and last column, and first and last row) that is initialized to ‘o’.

Solutions

Expert Solution

Answer 1 :-

public void initialize(int[][] array)
   {
       int i,j;
      
       for(i=0;i<5;i++)
       {
           for(j=0;j<5;j++)
           {
               if(i==j)
               {
                   array[i][j]=-1;
                  
               }
               else
               {
                   array[i][j]=i+j;
               }
              
           }
       }
      
      
       for(i=0;i<5;i++)
       {
           System.out.println();
           for(j=0;j<5;j++)
           {
               System.out.print(" " +array[i][j]);
           }
       }
      
   }

---------------------------------------------------------------------------

Answer 2:-

int[] totals(int[][] array)
   {
       int i,j;
      
       int size=array.length;
       int one_d_array[]=new int[size];
      
       for(i=0;i        {
           for(j=0;j            {
               one_d_array[i]=array[j][i];
           }
       }
      
       return one_d_array;
     
   }

---------------------------------------------------------------

Answer 3:-

int vowels(String[] alpha)
   {
       int i;
       int max_count = 0;
       int count[]=new int[alpha.length];
      
       for(i=0;i        {
      
       for (i=0; i < alpha[i].length(); i++) {
          
          
           char ch = alpha[i].charAt(i);
          
           if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u' || ch == 'A' || ch == 'E' || ch == 'I' || ch == 'O' || ch == 'U')
           {          
           count[i]=count[i]+1;
          
           }
          
           }
       }
      
       for(i=0;i        {
           max_count=count[0];
           if(count[i]>max_count)
           {
               max_count=count[i];  
           }
          
       }
       return max_count;
      
   }
  

----------------------------------------------------------------

Answer 4:-  

int count(int[] array, int min)
   {
       int tocount=0;
       int i;
      
       for(i=0;i        {
           if(array[i]>min)
           {
               tocount=tocount+1;
           }
       }
      
       return tocount;
   }

-------------------------------------------------------------------------------

Answer 5:-

void order(int[] digit)
   {
       int max=digit[0];
       int min=digit[0];
       int i;
       for(i=0;i        {
           if(digit[i]>max)
           {
               max=digit[i];
           }
             
           if(digit[i]< min)
           {
               digit[i]=min;
           }
             
       }
         
       System.out.println("Maximum Value is :"+max);
       System.out.println("Minimum Value is :"+min);
         
   }

---------------------------------------------------------------------------------------------------

Answer 6:-

int[] summit(int gamma[], int delta[])
   {
       int i,j;
       int[] array=new int[10];
       int size1=gamma.length;
       int size2=delta.length;
         
       if(size1==size2)             
       {
           for(i=0;i            {
               array[i]=gamma[i]+delta[i];
           }
             
       }
       else
       {
           for (i = 0; i < size1; i++) {
               array[i] = -1;
               }
       }
         
       return array;
         
   }

------------------------------------------------------------------------

Answer 7:-

void border(char[][] array)
   {
       int i,j;
          
           int size=array.length;
          
           for(i=0;i            {
               for(j=0;j                {
                   if(i==0 ||i==size-1 || j==0 ||j==size-1)
                   {
                       array[i][j]='o';
                   }
                   else
                   {
                       array[i][j]='x';  
                   }
               }
                  
           }
           for(i=0;i            {
               System.out.println();
               for(j=0;j                {
                   System.out.print(" " +array[i][j]);
               }
           }
         
   }


Related Solutions

Write a function named findIndex that takes an array of integers, the number of elements in...
Write a function named findIndex that takes an array of integers, the number of elements in the array, and two variables, such that it changes the value of the first to be the index of the smallest element in the array, and changes the value of the second to be the index of the largest element in the array. Please complete this in C++, using pass by reference
Write a function named findIndex that takes an array of integers, the number of elements in...
Write a function named findIndex that takes an array of integers, the number of elements in the array, and two variables, such that it changes the value of the first to be the index of the smallest element in the array, and changes the value of the second to be the index of the largest element in the array. Please complete this in C++
use java for : 1. Write a method called indexOfMax that takes an array of integers...
use java for : 1. Write a method called indexOfMax that takes an array of integers and returns the index of the largest element. 2. The Sieve of Eratosthenes is “a simple, ancient algorithm for finding all prime numbers up to any given limit” (https://en.wikipedia. org/wiki/Sieve_of_Eratosthenes).Write a method called sieve that takes an integer parameter, n, and returns a boolean array that indicates, for each number from 0 to n -1, whether the number is prime.
Implement a method that meets the following requirements: (a) Takes as parameter 1) an int array...
Implement a method that meets the following requirements: (a) Takes as parameter 1) an int array A 2) an int number x to search for (b) determines whether x exists in A, and prints a message indicating the result (c) has the best worst case Big Oh complexity you can manage, using only your own thinking and the materials (the worst case growth rate for the number of items searched should be as low as possible, given that A contains...
.. Write a method called findNums that takes a two-dimension array of integers as a parameter...
.. Write a method called findNums that takes a two-dimension array of integers as a parameter and returns the number of times a two-digit number appears in the array. For example, if the array (as created by the program below) is 10 45 3 8 2 42 3 21 44 The value returned would be 5 (there are 5 two-digit numbers in the array) public class Question2 {    public static void main(String args[]){      int arr[][] = {{10, 45,...
FOR JAVA Write a method called findNum that takes a two-dimension array of integers and an...
FOR JAVA Write a method called findNum that takes a two-dimension array of integers and an int as parameters and returns the number of times the integer parameter appears in the array. For example, if the array (as created by the program below) is 10 45 3 8 2 42 3 21 44 And the integer parameter is 3, the value returned would be 2 (the number 3 appears two times in the array) public class HomeworkA { public static...
Write a method, remove, that takes three parameters: an array of integers, the length of the array, and an integer called removeItem.
Java programming:Write a method, remove, that takes three parameters: an array of integers, the length of the array, and an integer called removeItem. The method should find and delete the first occurrence of removeItem in the array. If the value does not exist or the array is empty, output an appropriate message. (Note that after deleting the element, the array size is reduced by 1.) You may assume that the array is unsorted.Now re-do this exercise and name it ExInsertionSort....
Write a Java program to initialize an array with the even integers from 2 to 20...
Write a Java program to initialize an array with the even integers from 2 to 20 and print the result then pass this array to a method in order to create a new array which is the inverse of the array you passed (print the result). You cannot use a third array. Insert comments and version control in the program to document the program.
JAVA Implement a public class method named comparison on a public class Compare that accepts two...
JAVA Implement a public class method named comparison on a public class Compare that accepts two Object arguments. It should return 0 if both references are equal. 1 if both objects are equal. and -1 otherwise. (SUPER IMPORTANT) Either reference can be null, so you'll need to handle those cases carefully! Here is what I have so far: public class Compare { public static int comparison(Object a, Object b) {   if (a == null || b == null) {    return...
Create a method:         Public Static boolean isSubArray489(int[] intArray) This method has an array of integers as its...
Create a method:         Public Static boolean isSubArray489(int[] intArray) This method has an array of integers as its input parameter, we'll say that a SubArray 9,8,7is that three integers, 9,8,7values appearing decreasing order one by one in the array. Return true if the array does contain any SubArray “987” Notice that any 3 integers that presenting a decreasing by one order must return True. (987, 876,765,654, 543, 432,321, 210 are all True) Call this method in your main function, and pass in...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT