Question

Sorting an array: 2. Write a program that asks the user for 5 numbers and stores them in an array called data. Then call a me

LANGUAGE: JAVA

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.util.*;

public class Test
{
   public static void ArraySort(int []arr)
   {
       System.out.print("Original array : ");
       for(int i=0;i<arr.length;i++)
       System.out.print(arr[i]+" ");
       Arrays.sort(arr);
       System.out.println();
       System.out.print("Sorted array : ");
       for(int i=0;i<arr.length;i++)
       System.out.print(arr[i]+" ");
   }
   public static void main (String[] args)
   {
       Scanner sc=new Scanner(System.in);
       int []arr=new int[5];
       System.out.println("Enter 5 numbers : ");
       for(int i=0;i<5;i++)
       arr[i]=sc.nextInt();
       ArraySort(arr);
   }
}

OUTPUT:-

Success #stdin #stdout 0.16s 35964KB Enter 5 numbers : 936 7 2 Original array : 93672 Sorted array : 23679

// If any doubt please comment

Success #stdin #stdout 0.16s 35964KB Enter 5 numbers 9 3 6 7 2 Original array 9 3 6 7 2 Sorted array : 2 3 6 79

Add a comment
Know the answer?
Add Answer to:
LANGUAGE: JAVA Sorting an array: 2. Write a program that asks the user for 5 numbers...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a simple and short MIPS assembly language program that asks the user for 6 numbers,...

    Write a simple and short MIPS assembly language program that asks the user for 6 numbers, merge-sorts them, and then prints them out in ascending order comment each and every programme .(USING WINDOWS QtSpim) Note : This question is not giving desired solution may you please try it in a simple manner for six number inputed by the user.

  • In the Java language APCS Sorting Numbers Lab Write a program that reads in 3 floating-point...

    In the Java language APCS Sorting Numbers Lab Write a program that reads in 3 floating-point numbers (decimal numbers) and prints the three numbers in sorted order from smallest to largest. In your main method, create a scanner and get the 3 numbers from the user. Create a separate method called sort that accepts the 3 numbers prints them in the appropriate order. Sample Run#1 Please enter first number: 4 Please enter second number: 9 Please enter third number: 2.5...

  • Write C programs for the following: 1. Modify the sorting program you wrote in Lab 2...

    Write C programs for the following: 1. Modify the sorting program you wrote in Lab 2 so that it is modular. Write a function called sort that accepts an integer array, sorts it, and returns the sorted array to the main function. Call this function from the main program. In addition, write a subroutine called print_array that accepts an integer array and prints it out in this format: The array is [01 2 3456 7 8 9] Use this function...

  • Write a complete JAVA program to do the following program. The main program calls a method...

    Write a complete JAVA program to do the following program. The main program calls a method to read in (from an input file) a set of people's three-digit ID numbers and their donations to a charity (hint: use parallel arrays)Then the main program calls a method to sort the ID numbers into numerical order, being sure to carry along the corresponding donations. The main program then calls a method to print the sorted 1ists in tabular form, giving both ID...

  • C programing Write a program to sort numbers in either descending or ascending order. The program...

    C programing Write a program to sort numbers in either descending or ascending order. The program should ask the user to enter positive integer numbers one at a time(hiting the enter key after each one) The last number entered by the user should be -1, to indicate no further numbers will be entered. Store the numbers in an array, and then ask the user how to sort the numbers (either descending or ascending). Call a function void sortnumbers ( int...

  • can someone please help me with this. I need to use java. Recursion Write and run...

    can someone please help me with this. I need to use java. Recursion Write and run a program that reads in a set of numbers and stores them in a sequential array. It then calls a recursive function to sort the elements of the array in ascending order. When the sorting is done, the main function prints out the elements of the newly sorted array Hint: How do you sort an array recursively? Place the smallest element of the array...

  • Sorting Threads Assignment Overview Write a multithreaded sorting program in Java which uses the ...

    Sorting Threads Assignment Overview Write a multithreaded sorting program in Java which uses the merge sort algorithm. The basic steps of merge sort are: 1) divide a collection of items into two lists of equal size, 2) use merge sort to separately sort each of the two lists, and 3) combine the two sorted lists into one sorted list. Of course, if the collection of items is just asingle item then merge sort doesn’t need to perform the three steps,...

  • Write a Java program that has a method called arrayAverage that accepts an arrary of numbers...

    Write a Java program that has a method called arrayAverage that accepts an arrary of numbers as an argument and returns the average of the numbers in that array. Create an array to test the code with and call the method from main to print the average to the screen. The array size will be from a user's input (use Scanner). - array size = int - avergage, temperature = double - only method is arrayAverage Output:

  • Write a java program that asks the user to enter 2 integers, obtains them from the...

    Write a java program that asks the user to enter 2 integers, obtains them from the user, determines if they are even or odd numbers and prints their sum, product, difference, and quotient (Division).

  • Hi this program must be completed using a Eclipes Compiler for Java only . This is...

    Hi this program must be completed using a Eclipes Compiler for Java only . This is and intro to java class , so only intro methods should be used for this assignment. Please include a copy of the input data and a sample of the out put data . Thanks a bunch Homework-Topic 9-Donations Write a complete program to do the following: The main program calls a method to read in (Erom an input file) a set of people's three-digit...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT