Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Smallest Swap This exercise will require the searching and manipulation of an array using loops. The program will read in a positive integer nn from

Smallest Swap

This exercise will require the searching and manipulation of an array using loops.

The program will read in a positive integer nn from input. You should then add code to

  1. Create an array of that size.

  2. Read in that many numbers from the user (they will all be unique).

  3. Find the smallest number.

  4. Swap the smallest number with whatever is in the first cell of the array.

  5. Print out the numbers in the array in order each on a new line.

To keep things clean, there will be no additional prompts or print outs for this one.

For example, if 3 was entered, an array of size 3 should be created. If then the numbers 4, 5, 2 where entered, the program should print out

2

5

4

import java.util.Scanner;

public class SmallestSwap { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); //Let the looping begin! (and declare the array) //While this can be done in two loops, //if you're not sure, do the three //steps that require loops as separate loops. //Always remember, working is better than //perfect. } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beginning C# 2005 Databases

Authors: Karli Watson

1st Edition

0470044063, 978-0470044063

More Books

Students also viewed these Databases questions

Question

3. Describe phases of minority identity development.

Answered: 1 week ago

Question

2. What are your challenges in the creative process?

Answered: 1 week ago