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:   ...
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 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?
This is a three-part question. If you want it piecemeal, then let me know. Assume that...
This is a three-part question. If you want it piecemeal, then let me know. Assume that R31, R30, ... , R0 are the 32 ALU result bits output by our MIPS ALU. a) Write down a logic expression for the Z (zero) flag that indicates when the result is zero as a function of these 32 result bits. b) Write down a logic expression for an N (negative) flag that indicates whether the result is negative. c) Suppose that there...
Please let me know what the formulas are to calculate the following: I am seeing different...
Please let me know what the formulas are to calculate the following: I am seeing different answers and I don't know which is correct. E 15–26 Lease concepts; finance/sales-type leases; guaranteed and unguaranteed residual value Each of the four independent situations below describes a sales-type lease in which annual lease payments of $100,000 are payable at the beginning of each year. Each is a finance lease for the lessee. Determine the following amounts at the beginning of the lease: A....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT