SlideShare a Scribd company logo
1 of 1
Your task is to complete a method that swaps the first and second half of an array of integers. For
example, if the array contains the values
then after calling the method, it should contain the values
If the array contains an odd number of elements, leave the middle element in place. For example,
becomes
Complete the following code:
Solution
public class Swapper { /** This method swaps the first and second half of the given array.
@param values an array */ public void swapFirstAndSecondHalf(int[] values) { final int len =
values.length / 2; final int offset = values.length - len; for (int i = 0; i < len; i++) { int temp =
values[i]; values[i] = values[offset + i]; values[offset + i] = temp; } // This method is used to
check your work public int[] check(int[] values) { swapFirstAndSecondHalf(values); return
values; } }

More Related Content

Similar to Your task is to complete a method that swaps the first and second half.docx

----------Evaluator-java---------------- package evaluator- import j.docx
----------Evaluator-java---------------- package evaluator-   import j.docx----------Evaluator-java---------------- package evaluator-   import j.docx
----------Evaluator-java---------------- package evaluator- import j.docx
Adamq0DJonese
 
Java Code The traditional way to deal with these in Parsers is the .pdf
Java Code The traditional way to deal with these in Parsers is the .pdfJava Code The traditional way to deal with these in Parsers is the .pdf
Java Code The traditional way to deal with these in Parsers is the .pdf
stopgolook
 
The concept of stack is extremely important in computer science and .pdf
The concept of stack is extremely important in computer science and .pdfThe concept of stack is extremely important in computer science and .pdf
The concept of stack is extremely important in computer science and .pdf
arihantsherwani
 
C++ - UNIT_-_IV.pptx which contains details about Pointers
C++ - UNIT_-_IV.pptx which contains details about PointersC++ - UNIT_-_IV.pptx which contains details about Pointers
C++ - UNIT_-_IV.pptx which contains details about Pointers
ANUSUYA S
 
C++ Course - Lesson 2
C++ Course - Lesson 2C++ Course - Lesson 2
C++ Course - Lesson 2
Mohamed Ahmed
 
How do I fix it in LinkedList.javathis is what i didLabProgra.pdf
How do I fix it in LinkedList.javathis is what i didLabProgra.pdfHow do I fix it in LinkedList.javathis is what i didLabProgra.pdf
How do I fix it in LinkedList.javathis is what i didLabProgra.pdf
mail931892
 
golang_refcard.pdf
golang_refcard.pdfgolang_refcard.pdf
golang_refcard.pdf
Spam92
 
Copy your completed LinkedList class from Lab 3 into the LinkedList..pdf
Copy your completed LinkedList class from Lab 3 into the LinkedList..pdfCopy your completed LinkedList class from Lab 3 into the LinkedList..pdf
Copy your completed LinkedList class from Lab 3 into the LinkedList..pdf
facevenky
 
Below is the assignment description and the file I have written..pdf
Below is the assignment description and the file I have written..pdfBelow is the assignment description and the file I have written..pdf
Below is the assignment description and the file I have written..pdf
info673628
 

Similar to Your task is to complete a method that swaps the first and second half.docx (20)

----------Evaluator-java---------------- package evaluator- import j.docx
----------Evaluator-java---------------- package evaluator-   import j.docx----------Evaluator-java---------------- package evaluator-   import j.docx
----------Evaluator-java---------------- package evaluator- import j.docx
 
Python_Module_2.pdf
Python_Module_2.pdfPython_Module_2.pdf
Python_Module_2.pdf
 
Java Code The traditional way to deal with these in Parsers is the .pdf
Java Code The traditional way to deal with these in Parsers is the .pdfJava Code The traditional way to deal with these in Parsers is the .pdf
Java Code The traditional way to deal with these in Parsers is the .pdf
 
Lecture 8
Lecture 8Lecture 8
Lecture 8
 
Linq and lambda
Linq and lambdaLinq and lambda
Linq and lambda
 
C programming assignment help
C programming assignment helpC programming assignment help
C programming assignment help
 
data structures using C 2 sem BCA univeristy of mysore
data structures using C 2 sem BCA univeristy of mysoredata structures using C 2 sem BCA univeristy of mysore
data structures using C 2 sem BCA univeristy of mysore
 
Space Complexity in Data Structure.docx
Space Complexity in Data Structure.docxSpace Complexity in Data Structure.docx
Space Complexity in Data Structure.docx
 
03 function overloading
03 function overloading03 function overloading
03 function overloading
 
The concept of stack is extremely important in computer science and .pdf
The concept of stack is extremely important in computer science and .pdfThe concept of stack is extremely important in computer science and .pdf
The concept of stack is extremely important in computer science and .pdf
 
Extractors & Implicit conversions
Extractors & Implicit conversionsExtractors & Implicit conversions
Extractors & Implicit conversions
 
C++ - UNIT_-_IV.pptx which contains details about Pointers
C++ - UNIT_-_IV.pptx which contains details about PointersC++ - UNIT_-_IV.pptx which contains details about Pointers
C++ - UNIT_-_IV.pptx which contains details about Pointers
 
Functional object
Functional objectFunctional object
Functional object
 
C++ Course - Lesson 2
C++ Course - Lesson 2C++ Course - Lesson 2
C++ Course - Lesson 2
 
Data structures arrays
Data structures   arraysData structures   arrays
Data structures arrays
 
How do I fix it in LinkedList.javathis is what i didLabProgra.pdf
How do I fix it in LinkedList.javathis is what i didLabProgra.pdfHow do I fix it in LinkedList.javathis is what i didLabProgra.pdf
How do I fix it in LinkedList.javathis is what i didLabProgra.pdf
 
golang_refcard.pdf
golang_refcard.pdfgolang_refcard.pdf
golang_refcard.pdf
 
Computer programming 2 Lesson 13
Computer programming 2  Lesson 13Computer programming 2  Lesson 13
Computer programming 2 Lesson 13
 
Copy your completed LinkedList class from Lab 3 into the LinkedList..pdf
Copy your completed LinkedList class from Lab 3 into the LinkedList..pdfCopy your completed LinkedList class from Lab 3 into the LinkedList..pdf
Copy your completed LinkedList class from Lab 3 into the LinkedList..pdf
 
Below is the assignment description and the file I have written..pdf
Below is the assignment description and the file I have written..pdfBelow is the assignment description and the file I have written..pdf
Below is the assignment description and the file I have written..pdf
 

More from altonm

Nuclear disarmament should result in the retrieval of large amounts of.docx
Nuclear disarmament should result in the retrieval of large amounts of.docxNuclear disarmament should result in the retrieval of large amounts of.docx
Nuclear disarmament should result in the retrieval of large amounts of.docx
altonm
 
Often in science it is helpful to talk about a representative example.docx
Often in science it is helpful to talk about a representative example.docxOften in science it is helpful to talk about a representative example.docx
Often in science it is helpful to talk about a representative example.docx
altonm
 

More from altonm (20)

Nuclear disarmament should result in the retrieval of large amounts of.docx
Nuclear disarmament should result in the retrieval of large amounts of.docxNuclear disarmament should result in the retrieval of large amounts of.docx
Nuclear disarmament should result in the retrieval of large amounts of.docx
 
Nomenclature Practice Problems Ch 20 Part I For compounds represented.docx
Nomenclature Practice Problems Ch 20 Part I For compounds represented.docxNomenclature Practice Problems Ch 20 Part I For compounds represented.docx
Nomenclature Practice Problems Ch 20 Part I For compounds represented.docx
 
NO2 is a yellow gas responsible for the brownish haze that builds up p.docx
NO2 is a yellow gas responsible for the brownish haze that builds up p.docxNO2 is a yellow gas responsible for the brownish haze that builds up p.docx
NO2 is a yellow gas responsible for the brownish haze that builds up p.docx
 
No need for any sort of explanation- Please only a straightforward ans.docx
No need for any sort of explanation- Please only a straightforward ans.docxNo need for any sort of explanation- Please only a straightforward ans.docx
No need for any sort of explanation- Please only a straightforward ans.docx
 
No copy and paste from other website- must be in your own words- Thank.docx
No copy and paste from other website- must be in your own words- Thank.docxNo copy and paste from other website- must be in your own words- Thank.docx
No copy and paste from other website- must be in your own words- Thank.docx
 
nidly s wht is ment the er SolutionThe branch of science and technolog.docx
nidly s wht is ment the er SolutionThe branch of science and technolog.docxnidly s wht is ment the er SolutionThe branch of science and technolog.docx
nidly s wht is ment the er SolutionThe branch of science and technolog.docx
 
Newton Inc- uses a calendar year for financial reporting- The company (1).docx
Newton Inc- uses a calendar year for financial reporting- The company (1).docxNewton Inc- uses a calendar year for financial reporting- The company (1).docx
Newton Inc- uses a calendar year for financial reporting- The company (1).docx
 
olecular Forces liquid and sold states- molecules are held together by.docx
olecular Forces liquid and sold states- molecules are held together by.docxolecular Forces liquid and sold states- molecules are held together by.docx
olecular Forces liquid and sold states- molecules are held together by.docx
 
Okay- so I understand questions 1- however I don-'t get how to find ou.docx
Okay- so I understand questions 1- however I don-'t get how to find ou.docxOkay- so I understand questions 1- however I don-'t get how to find ou.docx
Okay- so I understand questions 1- however I don-'t get how to find ou.docx
 
ofa fallowing sormally wuma vp faest wee heot in appliod A) water B) w.docx
ofa fallowing sormally wuma vp faest wee heot in appliod A) water B) w.docxofa fallowing sormally wuma vp faest wee heot in appliod A) water B) w.docx
ofa fallowing sormally wuma vp faest wee heot in appliod A) water B) w.docx
 
Often in science it is helpful to talk about a representative example.docx
Often in science it is helpful to talk about a representative example.docxOften in science it is helpful to talk about a representative example.docx
Often in science it is helpful to talk about a representative example.docx
 
Obstacles in EHRs Implementation Discuss the major local- national- an.docx
Obstacles in EHRs Implementation Discuss the major local- national- an.docxObstacles in EHRs Implementation Discuss the major local- national- an.docx
Obstacles in EHRs Implementation Discuss the major local- national- an.docx
 
o be (11) Explain why an object (like a pencil) that is partially subm.docx
o be (11) Explain why an object (like a pencil) that is partially subm.docxo be (11) Explain why an object (like a pencil) that is partially subm.docx
o be (11) Explain why an object (like a pencil) that is partially subm.docx
 
Numerical Analysis- (Matlab) Write a program that computes an integral.docx
Numerical Analysis- (Matlab) Write a program that computes an integral.docxNumerical Analysis- (Matlab) Write a program that computes an integral.docx
Numerical Analysis- (Matlab) Write a program that computes an integral.docx
 
Yvon- an accountant- is charged with negligence by Zesty Sauce- Inc--.docx
Yvon- an accountant- is charged with negligence by Zesty Sauce- Inc--.docxYvon- an accountant- is charged with negligence by Zesty Sauce- Inc--.docx
Yvon- an accountant- is charged with negligence by Zesty Sauce- Inc--.docx
 
Your host has automatically received an IPv6 address working in conjun.docx
Your host has automatically received an IPv6 address working in conjun.docxYour host has automatically received an IPv6 address working in conjun.docx
Your host has automatically received an IPv6 address working in conjun.docx
 
Your community has decided to construct a hazardous waste facility for.docx
Your community has decided to construct a hazardous waste facility for.docxYour community has decided to construct a hazardous waste facility for.docx
Your community has decided to construct a hazardous waste facility for.docx
 
Young Corporation incurred research and development costs of $500-000.docx
Young Corporation incurred research and development costs of $500-000.docxYoung Corporation incurred research and development costs of $500-000.docx
Young Corporation incurred research and development costs of $500-000.docx
 
You work for a small city IT department- and you are reviewing compute.docx
You work for a small city IT department- and you are reviewing compute.docxYou work for a small city IT department- and you are reviewing compute.docx
You work for a small city IT department- and you are reviewing compute.docx
 
Your CEO is from the old school- What steps would you take to entice h.docx
Your CEO is from the old school- What steps would you take to entice h.docxYour CEO is from the old school- What steps would you take to entice h.docx
Your CEO is from the old school- What steps would you take to entice h.docx
 

Recently uploaded

1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
QucHHunhnh
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
negromaestrong
 

Recently uploaded (20)

Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Magic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptxMagic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptx
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Asian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptxAsian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptx
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptx
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 

Your task is to complete a method that swaps the first and second half.docx

  • 1. Your task is to complete a method that swaps the first and second half of an array of integers. For example, if the array contains the values then after calling the method, it should contain the values If the array contains an odd number of elements, leave the middle element in place. For example, becomes Complete the following code: Solution public class Swapper { /** This method swaps the first and second half of the given array. @param values an array */ public void swapFirstAndSecondHalf(int[] values) { final int len = values.length / 2; final int offset = values.length - len; for (int i = 0; i < len; i++) { int temp = values[i]; values[i] = values[offset + i]; values[offset + i] = temp; } // This method is used to check your work public int[] check(int[] values) { swapFirstAndSecondHalf(values); return values; } }