Question

In: Computer Science

Please let me know how to make code sort. If you put sort (sort 1000 6...

Please let me know how to make code sort.

If you put sort (sort 1000 6 5 4 3 2 1, not separate), you will get 1 2 3 4 5 6 1000.

sort 50 300 27 5

5 27 50 300

public static void main (String[] args) {
       Scanner scnr = new Scanner(System.in);
       String a = "";
           a = scnr.nextLine();
           String[] b = imput.split(" ")

if (b[0].equalsI("sort")) {

}

Please do not change above code.

Solutions

Expert Solution

Note: Could you plz go through this code and let me know if u need any changes in this.Thank You
_________________

// TestProg.java

import java.util.Scanner;

public class TestProg {

   public static void main(String[] args) {
       Scanner scnr = new Scanner(System.in);
       String a = "";
       a = scnr.nextLine();
       String[] b = a.split(" ");

       String temp;
       if (b[0].equals("sort")) {
           // This Logic will Sort the Array of elements in Ascending order

           for (int i = 1; i < b.length; i++) {
               for (int j = i + 1; j < b.length; j++) {

                   int num1 = Integer.parseInt(b[i]);
                   int num2 = Integer.parseInt(b[j]);
                   if (num1 > num2) {
                       temp = b[i];
                       b[i] = b[j];
                       b[j] = temp;
                   }
               }
           }
          
          
       }

       for(int i=1;i<b.length;i++)
       {
           System.out.print(b[i]+" ");
       }
   }

}
_________________________

Output:

sort 50 300 27 5
5 27 50 300

_______________Could you plz rate me well.Thank You


Related Solutions

please let me know reference of this MATLAB code. please explain this code line by line....
please let me know reference of this MATLAB code. please explain this code line by line. . . N=256; %% sampling number n=linspace(0,1,N); fs=1/(n(2)-n(1)); x=5*(sin((2*pi*10*n))); %% create signal N=length(x); f=[-fs/2:fs/N:fs/2-fs/N]; subplot(211) plot(f,fftshift(abs(fft(x)))); title('|G(f)|');grid; xlabel('frequency'); ylabel('|G(f)|'); %Zero padding xx=[zeros(1,128) x zeros(1,128)]; N=length(xx); f=[-fs/2:fs/N:fs/2-fs/N]; subplot(212) plot(f,fftshift(abs(fft(xx)))); title('|Gz(f)|');grid; xlabel('frequency'); ylabel('|Gz(f)|');
Hello! Please let me know, thank you! You have a credit card with a balance of...
Hello! Please let me know, thank you! You have a credit card with a balance of $13,600 and an APR of 18 percent compounded monthly. You have been making monthly payments of $260 per month, but you have received a substantial raise and will increase your monthly payments to $335 per month. How many months quicker will you be able to pay off the account? 37.39 Months 36.05 Months 40.06 Months 11.71 Months 34.33 Months Thank you!
How would I make a bubble sort and an optimized bubble sort with the code given?...
How would I make a bubble sort and an optimized bubble sort with the code given? I also need to implement a timer into each sort and display runtime with the sorts. NODE.H _______________________________________________________________________________________________________ /* node.h */ /* two classes 1: node.h 2. singlylinkedlist.h nod1 (value + pointer) ---> node2 ---> node3 ---> |||| <--- node.h ^ | singlylinkedlist ----------------*node head; */ #ifndef NODE_H #define NODE_H #include <iostream> using namespace std; class Node {    friend class singlyLinkedList; public:   ...
question 1 (explain each code) If more information if needed please let me know a)t=linspace(0,1,1000); %...
question 1 (explain each code) If more information if needed please let me know a)t=linspace(0,1,1000); % Time t Meaning: b) for i=1:1000 xt(i)=v*cos(theta*pi/180)*t(i); yt(i)=h+(v*sin(theta*pi/180)*t(i))-0.5*g*t(i)^2; end Meaning: c) k = find(yt<0,1) % find index at which distance becomes fprintf('Ball hits the ground at distance of %d meters',xt(k)) Meaning: d) x=0:0.1:max(xt); y=0; plot(x,y*ones(size(x)),'--k') Meaning:
Below is the only information I received for these questions. Please let me know if there...
Below is the only information I received for these questions. Please let me know if there is any additional info you may need. Any questions will help Federal Taxation I Module 8: Comprehensive Tax Return Project Jared and Ashley have come to you for help filing their 2018 tax return. They are married on December 31, 2018 and are both age 40. They live with their three qualifying children, Nick, Betty, and Roger, who are 12, 14, and 17 years...
Please answer in C++! Let me know if you have any questions about these. Program 1:...
Please answer in C++! Let me know if you have any questions about these. Program 1: For this program, imagine we want to track an object and detect if it goes off the left or right side of the screen (that is, it’s X position is less than 0 and greater than the width of the screen, say, 100). Write a program that asks the user for the starting X and Y position of the object as well as the...
Please let me know about the material structure and properties of Solar energy devices.
Please let me know about the material structure and properties of Solar energy devices.
Please use the code I provided!! Use either bubble sort or selection sort!! Thank you in...
Please use the code I provided!! Use either bubble sort or selection sort!! Thank you in advance This lab involves adding a sorting function to an existing C++ template. In this module, a file is provided for you -- SortableBag.h -- that implements a simple "bag" (unsorted collection of numbers) structure with array storage. Part 1 Add a sort() method to this template, which should not return any values or take any arguments ('void' for both the return type and...
It shows me that 1 error exists in this code but I didn't know how to...
It shows me that 1 error exists in this code but I didn't know how to fix this error so if you can help I will appreciate it. Language C++. Code: #include <iostream> #include <string> #include <iterator> #include <fstream> #include <sstream> #include <cstdlib> #include <set> using namespace std; class Book { private: string BookId; string BookISBN; string Publisher; int PublisherYear; double Price; int Quantity; string Author; public: string SetBookId(); string SetBookISBN(); string SetPublisher(); int SetPublisherYear(); double SetPrice(); int SetQuantity(); string...
This is a three-part question. If you want it piecemeal, then let me know. a) Why...
This is a three-part question. If you want it piecemeal, then let me know. a) Why do CISC processors tend to use micro-programming? b) Why do RISC processors not use micro-programming? c) What is the main advantage provided by a micro-programmed system?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT