Write a JAVA program to sort a given array of integers (1 Dimensional) in ascending order (from
smallest to largest). You can either get the array as input or hardcode it inside your program.
import java.util.*;
class BubbleSort
{
public static void main (String[] args)
{
Scanner input = new Scanner(System.in);
int[] num = new int[10];
System.out.println("Enter 10 integers : ");
for(int i = 0;i<10;i++)
{
num[i] = input.nextInt();
}
int temp;
for(int i=0; i<10; i++)
{
for(int j=1; j<10; j++)
{
if(num[j-1]> num[j]) // compare strings and swap using
ttemp
{
temp=num[j-1];
num[j-1]=num[j];
num[j]=temp;
}
}
}
System.out.println("Sorted integers : ");
for(int i = 0;i<10;i++)
{
System.out.print(num[i]+" ");
}
}
}
Output:
Enter 10 integers : 67 45 -9 -45 66 12 51 44 81 -10 Sorted integers : -45 -10 -9 12 44 45 51 66 67 81
Do ask if any doubt. Please upvote.
Write a JAVA program to sort a given array of integers (1 Dimensional) in ascending order...
C programming Strictly -
Write a program to sort an array of
integers via arrays of pointers to those integers as shown in the
figure.
Problem 1 (68 points): Write a program to sort an array of integers via arrays of pointers to those integers as shown in the figure. The code should contain the following functions: 1)to randomly generate an array of integer numbers; 2) to allocate memory and build the arrays of pointers as shown in the figure...
Write a program in MIPS assembly language that implements the DESCENDING bubble sort algorithm to sort a variable-sized array of signed 32-bit integers (words)that are read from the console. Be reminded that in a descending sort, the integers are sorted from the largest to the smallest. A “special value” 99999 will beused to signify the end of the input sequence. This value is not to be considered part of the input data set. However, any value greater than 99999 that...
JAVA Write a program that shows the contents of the array integers 5 7 4 9 8 5 6 3 each time a selection sort changes it while sorting the array into ascending order. Please provide code in text and snapshot of the program running. thanks!
Write a Java program with a single-dimension array that holds 11 integer numbers and sort the array using a bubble sort. Next, identify the median value of the 11 integers. Here are the steps your program must accomplish. algorithm (either flowchart or pseudocode) that you will use to write the program Step 1. Create an Place the algorithm in a Word document. 6. Ste the Step 2. Code the program in Eclipse and ensure the following steps are accomplished. 1....
Consider the Java program below to sort an array A in an ascending order. M, N, and K are positive integers, and A is an array of N nonnegative integers where 0 < A[i] < M for all i e {0,..., N -1}. In this program, list is a class of an integer list with the following methods. 1st.size(): returns the number of elements in the list lst 1st.get(i): returns the element at the i-th position in the list lst...
implement void Quick_Sort(int A[],int l,int r) to sort array of integers in ascending order using the first element as a pivot, you can add any parameter you want Note : you are only allowed to use java language
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...
Please write a Java program that does the following: Create an array of 100 integers. Store 100 random integers (between 1 and 100) in the array. Print out the elements of the array. Sort the array in ascending order. Print out the sorted array. Prompt the user to enter a number between 1 and 100. Search the array for that number and then display "Found" or "Not Found" message. Display each number from 1 to 100 and the number of...
In JAVA write a program that contains an array containing 10 integers (1 to 10). user insert an integer from (1 to 10) , method is library sort or gapped insertion sort that will each sort the array and print it out to the console.