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)|');
IN C ++ PLEASE CODE FOR BUBBLE SORT---Add code to sort the bowlers. You have to...
IN C ++ PLEASE CODE FOR BUBBLE SORT---Add code to sort the bowlers. You have to sort their parallel data also. Print the sorted bowlers and all their info . You can use a bubble sort or a shell sort. Make sure to adjust your code depending on whether or not you put data starting in row zero or row one. Sort by Average across, lowest to highest.  The highest average should then be on the last row.. When you sort...
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...
Programming language: Java If any more information is needed please let me know exactly what you...
Programming language: Java If any more information is needed please let me know exactly what you need. Though there are a bunch of files they are small and already done. Modify the driver file ,Starbuzz coffee, to be able to order each blend and be able to add each condiment to each of the blends. The price should be set accordingly. Be able to: order 1 of each type of beverage, add multiple toppings to each ordered beverage and use...
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.
The following flow chart is a bubble sort. Write the code for this sort. Make sure...
The following flow chart is a bubble sort. Write the code for this sort. Make sure you display each pass and comparison. Include comments.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT