Question

Write a method swapArrayEnds() that swaps the first and last elements of its array parameter. Ex: sortArray = {10, 20, 30, 40in java please fix code between 14 and 20 to make the code compile

0 0
Add a comment Improve this question Transcribed image text
Answer #1

`Hey,

Note: If you have any queries related to the answer please do comment. I would be very happy to resolve all your queries.

Your code will work only for the test case given but not for others. Below is the modified code

public static void swapArrayEnds(int sortedArray[])

{

int temp=sortedArray[0];

sortedArray[0]=sortedArray[sortedArray.length-1];

sortedArray[sortedArray.length-1]=temp;

}

Kindly revert for any queries

Thanks.

Add a comment
Know the answer?
Add Answer to:
in java please fix code between 14 and 20 to make the code compile Write a...
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
  • C++ Write a function SwapArrayEnds() that swaps the first and last elements of the function's array...

    C++ Write a function SwapArrayEnds() that swaps the first and last elements of the function's array parameter. Ex: sortArray = {10, 20, 30, 40} becomes {40, 20, 30, 10}. The array's size may differ from 4. #include <iostream> using namespace std; /* Your solution goes here */ int main() {    const int SORT_ARR_SIZE = 4;    int sortArray[SORT_ARR_SIZE];    int i = 0;    sortArray[0] = 10;    sortArray[1] = 20;    sortArray[2] = 30;    sortArray[3] = 40;...

  • Write a method swapArrayEnds0 that swaps the first and last elements of its array parameter. Ex:...

    Write a method swapArrayEnds0 that swaps the first and last elements of its array parameter. Ex: sortArray-10, 20, 30, 40 becomes (40, 20, 30, 10). The array's size may differ from 4. 1 import java.util.Scanner; 3 public class ModifyArray 4 5 Display array values 6 public void displayValues(intarrayVals) 7 int i; for (i-o; i < arrayvals.length; ++?) { 10 System.out.printCarrayValsCi] +); System.out.println("); 12 13 14 15/ Your solution goes here*/ 16

  • Please write where its written write your code here!! please use java for the code! please...

    Please write where its written write your code here!! please use java for the code! please use the given code and I will rate thanks Magic index in an array a[1..n] is defined to be an index such that a[ i ] = i. Given an array of integers, write a recursive method to find the first magic index from left to right. If one exists in the given array, return the index number i, otherwise return -1. Here are...

  • 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...

  • 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...

  • please illistrate a UML diagram for the following code bellow, it should have 3 rows, 1...

    please illistrate a UML diagram for the following code bellow, it should have 3 rows, 1 colum like the one bellow, first box should have the class name, second box is for class attributes, and third box should have the class operations/methods and please put a (+) for public and a (-) for private example: class +-attributes +-Operations Also make a JAVADOCs, but not generated by a compiler, to explain what is going on in the code import java.util.Random; public...

  • Computer Science - Java Explain the code step by step (in detailed order). Also explain what...

    Computer Science - Java Explain the code step by step (in detailed order). Also explain what the program required. Thanks 7 import java.io.File; 8 import java.util.Scanner; 9 import java.util.Arrays; 10 import java.io.FileNotFoundException; 12 public class insertionSort 13 14 public static void insertionSort (double array]) 15 int n -array.length; for (int j-1; j < n; j++) 17 18 19 20 21 double key - array[j]; int i-_1 while ( (i > -1) && ( array [i] > key array [i+1] -...

  • this is a while array mystery from java. please help me to write the code for...

    this is a while array mystery from java. please help me to write the code for this question to run it on eclipse !! I want the full code to run this program !! Consider the following method: public static void arrayMystery (int[] a) { for (int i = a. length - 1; i >= 1; i--) { if (a[i] > ali - 1] + 10) { ali - 1] = a[i - 1] + 5; Indicate in the right-hand...

  • Type, Compile, Run all syntactically complete or mostly complete example code .You may need to change...

    Type, Compile, Run all syntactically complete or mostly complete example code .You may need to change some syntax to make them compile and run import java.io.*; import java.lang.*; import java.util.*; class MyThreadExampleMutex{ public static void main(String[] args) { new HelloThread (1). start (); new HelloThread (2). start (); new HelloThread (3). start (); System.out.print("Global.buffer Content = "); for (int i = 0; i < 9; i++) { System.out.print(Global.buffer[i] + "; "); }} } class Global { public static int[] buffer...

  • In the most basic/easiest JAVA please change the following code into RECURISON make sure the prog...

    In the most basic/easiest JAVA please change the following code into RECURISON make sure the program complies correctly. (It is currently in iterative.) please show comments how they are different after. //public class public class MergeSort { public static void mergeSort(int[] array) { int start; int i; int minScan; int minValue; int counter = 0; /** The outer loop iterates once for each element in the array. The start variable marks the position where the scan should begin. **/ for(start...

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
ADVERTISEMENT