Question

write static method in main driver class public static int[] combineTwoToOne(int[][] number); example DA is: 1...

write static method in main driver class

public static int[] combineTwoToOne(int[][] number);

example DA is:

1 2 3

4 5 6

returned 1D array is 1 2 3 4 5 6

0 0
Add a comment Improve this question Transcribed image text
Answer #1
public static int[] combineTwoToOne(int[][] number){
  if(number!=null) {
    int count = 0;
    for(int i = 0;i<number.length;i++){
      for(int j = 0;j<number[i].length;j++){
        count += 1;
      }
    }
    int arr[] = new int[count];
    int k = 0;
    for(int i = 0;i<number.length;i++){
      for(int j = 0;j<number[i].length;j++){
        arr[k++] = number[i][j];
      }
    }
    return arr;
  }
  return null;
}

Add a comment
Know the answer?
Add Answer to:
write static method in main driver class public static int[] combineTwoToOne(int[][] number); example DA is: 1...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Q21 Read the following code: 8 Points public class Main { public static int[][] doStuff() {...

    Q21 Read the following code: 8 Points public class Main { public static int[][] doStuff() { int[][] array2D = new int[3][2]; for (int i = 0; i < array2D.length; i++) { for (int j = 0; j < array2D[0].length; j++) { array2D[i][j] = (i+j)%2; } } return array2D; فه public static void main(String[] args) { int[][] a = doStuff(); مہ سره Q21.1 What are the contents of array a? 6 Points Write your answer as if printing the elements row-by-row....

  • Java: Write a class ArrayIntersection that implements the method below. public static int[] get(int[] one, int[]...

    Java: Write a class ArrayIntersection that implements the method below. public static int[] get(int[] one, int[] two) Given two arrays, it returns a new array with all values that are in both arrays. The returned array has a size fitting its elements exactly and without duplicates. The order of values does not matter. For example, given {1,5,5,1} and {5,3}, the method returns {5}.

  • JAVA~ 1. Write a static method named countOdd(my_array) that returns the number of odd integers in...

    JAVA~ 1. Write a static method named countOdd(my_array) that returns the number of odd integers in a given array. If there are no odd numbers in the array, the method should return 0. If the array is empty, the method should also return 0. For example: Test Result System.out.println(countOdd(new int[]{2, 3, 5, 6})); 2 System.out.println(countOdd(new int[]{2})); 0 System.out.println(countOdd(new int[]{})); 0 System.out.println(countOdd(new int[]{-7, 2, 3, 8, 6, 6, 75, 38, 3, 2})); 4 public static int ----------------------------------------------------------------------------------------------------------- 2. Write a static...

  • What is the Java output? Part One: class Driver { public static void main(String[] args) {...

    What is the Java output? Part One: class Driver { public static void main(String[] args) { int a = 5; int b = 3; if (a < b || a * 2 < b) System.out.print(a - b); System.out.print(b + a); } } Part Two: class Driver { public static void main(String[] args) { int a = 5; int b = 8; if (a < b) if (a * 2 < b) System.out.print("foo"); else System.out.print("bar"); else System.out.print("buz"); } }

  • In the following program: public  class Problem2{     public static int sample(int x, int y){         int z;         .........

    In the following program: public  class Problem2{     public static int sample(int x, int y){         int z;         ......      }     public static void  main(String[] args)     {          int a, b;          ......          sample(a,b);     } } (1) What is the return type of sample? (2) What are the local variables of sample? (3) What are the parameters of sample? (4) What are the arguments of sample? (5) Is sample a per-object method? Or a per-class method? (6) Is sample a public method, or private method?

  • public class PracticeExam { public static void main(String[] args) { int[][] data = { { 0,...

    public class PracticeExam { public static void main(String[] args) { int[][] data = { { 0, 1, 2, 3, 4, 5, 6 }, { 0, 1, 2, 3, 4, 5, 6 }, { 0, 1, 2, 3, 4, 5, 6 }, { 0, 1, 2, 3, 4, 5, 6 }, { 0, 1, 2, 3, 4, 5, 6 }, { 0, 1, 2, 3, 4, 5, 6 }, { 0, 1, 2, 3, 4, 5, 6 }, { 0, 1,...

  • Programming 3_4: Write the method public static int rangeProduct(int a, int b). Assume that a <...

    Programming 3_4: Write the method public static int rangeProduct(int a, int b). Assume that a < b. Your method must compute and return the product of the integers in the range from a to b. For example, if a = 3 and b = 6, your method would compute and return the product 3 × 4 × 5 × 6 = 360. public static int rangeProduct(int a, int b) {...}

  • public class FirstLastNameEvent { public final static int ppg = 35; public final static int cutoff...

    public class FirstLastNameEvent { public final static int ppg = 35; public final static int cutoff = 50; private String eventNumber; private int guestNumber; private int price; public void setEventNumber(String eventNumber) { this.eventNumber = eventNumber; } public void setGuestNumber(int guestNumber) { this.guestNumber = guestNumber * ppg; } public String getEventNumber() { return eventNumber; } public int getGuestNumber() { return guestNumber; } public int getPrice() { return price; } } Using Assignment #3’s code:(the code above) Modify the ‘public static void...

  • JAVA 1.Write a static method named getMaxEven(numbers) which takes an array of positive integers as a...

    JAVA 1.Write a static method named getMaxEven(numbers) which takes an array of positive integers as a parameter. This method calculates and returns the largest even number in the list. If there are no even numbers in the array, the method should return 0. You can assume that the array is not empty. For example: Test Result int[] values = {1, 4, 5, 9}; System.out.println(getMaxEven(values)); 4 System.out.println(getMaxEven(new int[]{1, 3, 5, 9})); 0 public static int --------------------------------------------------------------------------------- 2. Write a static method...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT