Question

I need to make this code access the main method I suppose, but I don't know...

I need to make this code access the main method I suppose, but I don't know how to make that happen... Help please!

QUESTION:

Write a method called switchEmUp that accepts two integer arrays as parameters and switches the contents of the arrays. Make sure that you have code which considers if the two arrays are different sizes.

Instructor comment: This will work since you never go back to the main method, but if you did, it wouldn't print out correctly.

MY CODE:
public class ArraySwap 
{
    private static int[] arr1 = new int[] {1, 2, 3, 4, 5, 6};
    private static int[] arr2= new int[] {7, 8, 9};

    public static void main(String[] args) 
    {
        switchEmUp(arr1,arr2);
    }
    public static void switchEmUp(int[] arr1,int[] arr2)
    {
        System.out.println();
        for (int n : arr1) 
        {
            System.out.print(n + "\t");
        }
        System.out.println();
        for (int n : arr2) 
        {
            System.out.print(n + "\t");
        }
        System.out.println();

        int[] temp = arr1;
        arr1 = arr2;
        arr2 = temp;

        System.out.println();
        for (int n : arr1) 
        {
            System.out.print(n + "\t");
        }
        System.out.println();
        for (int n : arr2) 
        {
            System.out.print(n + "\t");
        }
        System.out.println();
    }
}
0 0
Add a comment Improve this question Transcribed image text
Request Professional Answer

Request Answer!

We need at least 10 more requests to produce the answer.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the answer will be notified once they are available.
Know the answer?
Add Answer to:
I need to make this code access the main method I suppose, but I don't know...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Similar Homework Help Questions
  • I need to program 3 and add to program 2 bellows: Add the merge sort and...

    I need to program 3 and add to program 2 bellows: Add the merge sort and quick sort to program 2 and do the same timings, now with all 5 sorts and a 100,000 element array. Display the timing results from the sorts. DO NOT display the array. ____________________>>>>>>>>>>>>>>>>>>>>___________________________ (This is program 2 code that I did : ) ---->>>>>> code bellow from program 2 java program - Algorithms Write a program that randomly generates 100,000 integers into an array....

  • The following code is a Java code for insertion sort. I would like this code to...

    The following code is a Java code for insertion sort. I would like this code to be modified by not allowing more than 10 numbers of integer elements (if the user enters 11 or a higher number, an error should appear) and also finding the range of the elements after sorting. /* * Java Program to Implement Insertion Sort */ import java.util.Scanner; /* Class InsertionSort */ public class InsertionSortTwo { /* Insertion Sort function */ public static void sort( int...

  • Need // descriptions for each line of code that is relevant (Example, a description of "arr[i]=r.nextInt(100)+1;".Will...

    Need // descriptions for each line of code that is relevant (Example, a description of "arr[i]=r.nextInt(100)+1;".Will give positive rate import java.util.Random; public class TestApp { public static void main(String[] args) {    int arr[]=new int[11];    Random r = new Random(); //Random function for generation of random numbers    for(int i=0;i<arr.length;i++) //        arr[i]=r.nextInt(100)+1;    printArray(arr);    System.out.println();    bubbleSort(arr);    printArray(arr);    System.out.println();    System.out.println("Median : "+(arr[arr.length/2])); } private static void printArray(int[] aArray) {    for (int i...

  • The following code skeleton contains a number of uncompleted methods. With a partner, work to complete...

    The following code skeleton contains a number of uncompleted methods. With a partner, work to complete the method implementations so that the main method runs correctly: /** * DESCRIPTION OF PROGRAM HERE * @author YOUR NAME HERE * @author PARTNER NAME HERE * @version DATE HERE * */ import java.util.Arrays; import java.util.Random; import java.util.Scanner; public class ArrayExercises { /** * Given a random number generator and a length, create a new array of that * length and fill it from...

  • the code needs to be modifed. require a output for the code Java Program to Implement...

    the code needs to be modifed. require a output for the code Java Program to Implement Insertion Sort import java.util.Scanner; /Class InsertionSort * public class Insertion Sort { /Insertion Sort function */ public static void sort( int arr) int N- arr.length; int i, j, temp; for (i-1; i< N; i++) j-i temp arrli; while (j> 0 && temp < arrli-1) arrli]-arrli-1]; j-j-1; } arrlj] temp; /Main method * public static void main(String [] args) { Scanner scan new Scanner( System.in...

  • /** this is my code, and I want to invoke the method, doubleArraySize() in main method....

    /** this is my code, and I want to invoke the method, doubleArraySize() in main method. and I need to display some result in cmd or terminal. also, I have classes such as Average and RandomN needed for piping(pipe). please help me and thank you. **/ import java.util.Scanner; public class StdDev { static double[] arr; static int N; public static void main(String[] args) { if(args.length==0){ arr= new double[N]; Scanner input = new Scanner(System.in); int i=0; while(input.hasNextDouble()){ arr[i] = i++; }...

  • please evaluate the following code. this is JAVA a. class Car { public int i =...

    please evaluate the following code. this is JAVA a. class Car { public int i = 3; public Car(int i) { this.i = i; } } ... Car x = new Car(7), y = new Car(5); x = y; y.i = 9; System.out.println(x.i); b. class Driver { public static void main(String[] args) { int[] x = {5, 2, 3, 6, 5}; int n = x.length; for (int j = n-2; j > 0; j--) x[j] = x[j-1]; for (int j...

  • how to call maze1 and maze2 object to be use in print method maze2.maze[i][j] maze2 is...

    how to call maze1 and maze2 object to be use in print method maze2.maze[i][j] maze2 is object maze[i][j] is variable from different class i just need help in calling object to be used in the print method and main will call print method to display. import java.io.*; public class MazeSolver {        //=========================================== // object reader //==========================================    public static void read()throws FileNotFoundException,IOException{              reader maze1 = new reader(new FileReader("maze1.txt"));        reader maze2 = new reader(new...

  • I need a shoppingcartmanager.java that contains a main method for this code in java Itemtopurchase.java public...

    I need a shoppingcartmanager.java that contains a main method for this code in java Itemtopurchase.java public class ItemToPurchase {    // instance variables    private String itemName;    private String itemDescription;    private int itemPrice;    private int itemQuantity;    // default constructor    public ItemToPurchase() {        this.itemName = "none";        this.itemDescription = "none";        this.itemPrice = 0;        this.itemQuantity = 0;    }    public ItemToPurchase(String itemName, int itemPrice, int itemQuantity,String itemDescription) {   ...

  • I need help with adding comments to my code and I need a uml diagram for...

    I need help with adding comments to my code and I need a uml diagram for it. PLs help.... Zipcodeproject.java package zipcodesproject; import java.util.Scanner; import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; public class Zipcodesproject { /** * @param args the command line arguments */ public static void main(String[] args) { Scanner input=new Scanner(System.in); BufferedReader reader; int code; String state,town; ziplist listOFCodes=new ziplist(); try { reader = new BufferedReader(new FileReader("C:UsersJayDesktopzipcodes.txt")); String line = reader.readLine(); while (line != null) { code=Integer.parseInt(line); line =...

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