Question

In: Computer Science

Write a method which is passed A[], which is an array of int, and an int...

Write a method which is passed A[], which is an array of int, and an int passingScore. The method returns the number of items in A[] which are greater than or equal to passingScore.

Write a method which is passed an array of int A[]. The method returns true if A[] is the same backwards and forwards.

Write a method same( ), which is passed two arrays of int. The method returns true if the two arrays contain exactly the same contents.

Write a method called copy, which is passed A[], which is an array of int. The method returns a new array consisting of exactly the same items in A[].

Write a method called copy, which is passed A[], which is an array of int, and an integer n. The method returns a new array consisting of the first n items in A[].

Write a method called slice, which is passed A[], which is an array of int, an integer i and an integer j. The method returns a new array consisting of all of the items in A from A[i] to A[j] inclusive.

Write a method called copy, which is passed A[], which is an array of int, and an integer n. The method returns a new array consisting of all of the items in A[] which are greater or equal to n.

Write a method which is passed an array of int and returns true if the array is sorted in ascending order.

Write a method called generateTriangleNumbers(). This method will take in an integer x and will return an array of integers containing the first x triangle numbers. The nth triangle number is the sum of 1 + 2 + 3 + 4...(n − 1) + n.

generateTriangleNumbers(3) returns the array {1,3,6}

generateTriangleNumber(1) returns the array {1}

generateTriangleNumbers(7) returns the array {1, 3, 6, 10, 15, 21, 28}

Write a method which is passed a String and returns the String in reverse.

Write a method which is passed an array of String and modifies it so that all the Strings in the array are reversed. For example, if we pass the array: {"apple", "banana", "racecar", "abc"} the method transforms it to: {"elppa", "ananab", "racecar", "cba"}

Write a method which is passed a two-dimensional array of int row by row. Do not assume that each row has the same number of columns.

Write a method which is passed a two-dimensional array of int column by column.

Implement the method:

/* sets every value in A[][] to initVal */
public static void initialize(int A[][], int initVal) 
    

Implement the method:

/* returns the largest element in A */
public static int largestItem(int A[][]) 
    

Implement the method:

/* returns the sum of the row in A that has the largest
 * sum. */
public static int largestRow(int A[][]) 
    

Implement the method:

/* Returns column i of A as an array. For example, if */
/* A[][] is: */
/* |-----+-----+-----+-----+-----| */
/* |  10 |  20 |  30 |  40 |  50 | */
/* |-----+-----+-----+-----+-----| */
/* |  60 |  70 |  80 |  90 | 100 | */
/* |-----+-----+-----+-----+-----| */
/* | 110 | 120 | 130 | 140 | 150 | */
/* |-----+-----+-----+-----+-----| */
/* and i is 1, the method returns the array */
/*                                 */
/*   |----+----+-----|             */
/*   | 20 | 70 | 120 |             */ 
/*   |----+----+-----|             */
/*                                 */
/* You may assume that every row has */
/* the same number of columns. */
public static int[] getCol(int A[][], int i)
    

Implement the method:

/* returns the sum of the column in A that has the largest
 * sum. You may assume that each row has the same number
 * of columns. */
public static int largestCol(int A[][])

Solutions

Expert Solution

//program

public class Method {

public static int Larger(int A[],int passingScore) {

int count=0;

for(int i=0;i<A.length;i++) {

if(A[i]>=passingScore)count++;

}

return count;

}

public static boolean palindrom(int A[],int passingScore) {

int i=0,j=A.length-1;

while(i<j) {

if(A[i]!=A[j])return false;

}

return true;

}

public static boolean same(int A[],int B[]) {

if(A.length !=B.length)return false;

for(int i=0;i<A.length;i++) {

if(A[i]!=B[i])return false;

}

return true;

}

public static int[] copy(int A[]) {

int B[] = new int[A.length];

for(int i=0;i<A.length;i++) {

B[i] = A[i];

}

return B;

}

public static int[] copy(int A[],int n) {

int B[] = new int[n];

for(int i=0;i<n&&i<A.length;i++) {

B[i] = A[i];

}

return B;

}

public static int[] slice(int A[],int i ,int j) {

int B[] = new int[j-i+1];

int k=0;

for(;i<=j;i++) {

B[k] = A[i];

k++;

}

return B;

}

public static int[] copyn(int A[],int n) {

int count=0;

for(int i=0;i<A.length;i++) {

if(A[i]>=n)count++;

}

int B[] = new int[count];

int k=0;

for(int i=0;i<A.length;i++) {

if(A[i]>=n)B[k++] = A[i];

}

return B;

}

public static int [] generateTriangleNumbers(int x){

int B[] = new int[x];

B[0]=1;

for(int i=1;i<x;i++) {

B[i]=B[i-1]+i+1;

}

return B;

}

public static String[] reversestring(String str[]) {

String s[] = new String[str.length];

for(int i=0;i<s.length;i++)s[i]="";

for(int k=0;k<str.length;k++) {

for(int i=str[k].length()-1;i>=0;i--) {

s[k]+=str[k].charAt(i);

}

}

return s;

}

public static void initialize(int A[][], int initVal) {

for(int i=0;i<A.length;i++) {

for(int j=0;j<A[i].length;j++) {

A[i][j] = initVal;

}

}

}

public static int largestItem(int A[][]) {

int max=A[0][0];

for(int i=0;i<A.length;i++) {

for(int j=0;j<A[i].length;j++) {

if(A[i][j] >max)max=A[i][j];

}

}

return max;

}

public static int largestRow(int A[][]) {

int largest = A[0][0];

int sum;

for(int i=0;i<A.length;i++) {sum=0;

for(int j=0;j<A[i].length;j++) {

sum+=A[i][j];

}

if(sum>largest)largest = sum;

}

return largest;

}

public static int[] getCol(int A[][], int i) {

int column = A[0].length;

int row = A.length;

int B[] = new int [column];

for(int j=0;j<row;j++) {

B[j] = A[j][i];

}

return B;

}

public static int largestCol(int A[][]) {

int largest = A[0][0];

int sum;

int column = A[0].length;

int row = A.length;

for(int i=0;i<column;i++) {sum=0;

for(int j=0;j<row;j++) {

sum+=A[j][i];

}

if(sum>largest)largest = sum;

}

return largest;

}

}


Related Solutions

In Java: Write a method called copy, which is passed A[], which is an array of...
In Java: Write a method called copy, which is passed A[], which is an array of int, and an integer n. The method returns a new array consisting of the first n items in A[]. Write a method called slice, which is passed A[], which is an array of int, an integer i and an integer j. The method returns a new array consisting of all of the items in A from A[i] to A[j] inclusive.
Write a static method remove(int v, int[] in) that will return a new array of the...
Write a static method remove(int v, int[] in) that will return a new array of the integers in the given array, but with the value v removed. For example, if v is 3 and in contains 0, 1, 3, 2, 3, 0, 3, and 1, the method will return an array containing 0, 1, 2, 0, and 1. Hint: You can follow two steps to solve this problem: Create an array in the method, let say you called it result....
Which row has the largest sum? Write a method that takes a 2D int array and...
Which row has the largest sum? Write a method that takes a 2D int array and prints: of The index of the row that has the largest sum The sum of elements in that row java
Write a function, hexDigits that when passed an int array of any length greater than 0...
Write a function, hexDigits that when passed an int array of any length greater than 0 will print the corresponding hex digit for each int, one per line. The corresponding hex digit should be determined using a switch statement. The hex digits must be printed in uppercase and in order starting with the first entry. Each line of output should start with the array index of the number being written out, followed by a space, then the number, then another...
Write a java method that takes a string and returns an array of int that contains...
Write a java method that takes a string and returns an array of int that contains the corresponding alphabetic order of each letter in the received string: An illustration: the method takes: "Sara" the method returns: {4,1,3,2} another illustration: the method takes: "hey" the method returns: {2,1,3}
3. Array Operations 3-1 Write a function, equalsArray that when passed two int arrays of the...
3. Array Operations 3-1 Write a function, equalsArray that when passed two int arrays of the same length that is greater than 0 will return true if every number in the first array is equal to the number at the same index in the second array. If the length of the arrays is less than 1 the function must return false. For example, comparing the two arrays, {1,2,3,4,5} and {1,2,3,4,5} would return true but the two arrays {3,7} and {3,6}...
3. Write a program which divides a given array (int array []) into two parts: -...
3. Write a program which divides a given array (int array []) into two parts: - Left part with all elements with values <= (less than or equal) pivot (int pivot) and the - Right part with all elements with values > (larger than) pivot. You should ask the user to enter the values of: int pivot, int size and the array
In C++ Write a function which takes two parameters: an array of ints and an int...
In C++ Write a function which takes two parameters: an array of ints and an int size of the array and prints every element greater than 5 to the screen. As an example, if the array has the following 10 elements: 2 5 8 9 7 1 0 2 6 3, your function should print out 8 9 7 6. You may assume that the parameters passed to the function are valid. Your function must have the following signature: void...
Write a method public static void minMax(int[] arr) that takes an array of unique ints of...
Write a method public static void minMax(int[] arr) that takes an array of unique ints of length at least two as an argument, and swaps the smallest value of the array into the 0th position and swaps the largest value of the array into the last position. For example, if int[] a = {4, 3, 2, 6, 1, 5}, the method call minMax(a) should modify the array so that it is {1, 3, 2, 5, 4, 6}. The method should...
write a program in C Write a function that is passed an array of characters containing...
write a program in C Write a function that is passed an array of characters containing letter grades of A, B, C, D, and F, and returns the total number of occurrences of each letter grade. Your function should accept both lower and upper case grades, for example, both 'b' and 'B' should be bucketed into your running total for B grades. Any grade that is invalid should be bucketed as a grade of 'I' for Incomplete. You must use...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT