Question

Create a class with an array of type integer of size 15. Fill the array with...

Create a class with an array of type integer of size 15. Fill the array with random integers of size 1 to 1000. Sort the array. Print out the contents of the array.

Thank you in advance

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

Code for creating class with array, Sorting it and printing the contents of the array:

Output:

Above code:

import java.util.*;

import java.lang.*;

import java.io.*;

// Class Main

class Main

{

public static void main (String[] args) throws java.lang.Exception

{

// Array of the size 15

int Arraysize = 15;

// Filling the array with random integers from 1 to 1000.

int array[] = {1, 88, 256, 44, 166, 228, 94, 99, 724, 888, 2, 34, 48, 456, 1000};

// Sorting the above array

for(int i=0; i<Arraysize; i++)

{

for(int j=i+1; j<Arraysize; j++)

{

if(array[i] > array[j])

{

int temp = array[i];

array[i] = array[j];

array[j] = temp;

}

}

}

// Printing Sorted Array

System.out.println("Contents of array after sorting:");

for(int i=0; i<Arraysize; i++)

{

System.out.println(array[i]);

}

}

}

Add a comment
Know the answer?
Add Answer to:
Create a class with an array of type integer of size 15. Fill the array with...
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 java program that create a 2 dimensional array of type double of size 10...

    Write a java program that create a 2 dimensional array of type double of size 10 by 10. Fill the array with random numbers using a random number generator. Print the array contents. Write a java program that creates a file called data.txt that uses the PrintWriter class. Write the numbers 1 to 42 into the file. Close the file. Attach both files. Thank you in advance

  • Task 1 Main Function: Declare and fill an array with 1000 random integers between 1 -...

    Task 1 Main Function: Declare and fill an array with 1000 random integers between 1 - 1000. You will pass the array into functions that will perform operations on the array. Function 1: Create a function that will output all the integers in the array. (Make sure output is clearly formatted. Function 2: Create a Function that will sum and output all the odd numbers in the array. Function 3: Create a Function that will sum and output all the...

  • 1. Write a C code that do the following: Generate array of random integer numbers of...

    1. Write a C code that do the following: Generate array of random integer numbers of size 25 Fill the array with random integers ranging from [1-100] Find the maximum number of the array and its location Find the minimum number of the array and its location Search for a number in the array Print the array Flip the array Sort this array Quit the program when the user choose to exit

  • Create a new class called DemoSortingPerformacne Create a private method called getRandomNumberArray. It returns an array...

    Create a new class called DemoSortingPerformacne Create a private method called getRandomNumberArray. It returns an array of Integer and has 2 parameters: arraySize of type int and numberOfDigits of type int. This method should create an array of the specified size that is filled with random numbers. Each random numbers should have the same number of digits as specified in the second parameter In your main method (or additional private methods) do the following: Execute selection sort on quick sort...

  • Using Java: Create an array with the size of 10 and assign student details (Name, ID,...

    Using Java: Create an array with the size of 10 and assign student details (Name, ID, age and TotalMarks) to the array. Perform the Heap Sort to sort the students in ascending order based on their total marks. Steps: • Create the student list (use Random class in java to generate the age (15- 25) and total (0-100)) • Print the Student List in a table format • Perform Heap sort based on the total marks of the students •...

  • (+30) Provide a python program which will Populate an array(list) of size 25 with integers in...

    (+30) Provide a python program which will Populate an array(list) of size 25 with integers in the range -100 (negative 100)   to +100 inclusive Display the array and its length (use the len function) Display the average of all the integers in the array Display the number of even integers (how many) Display the number of odd integers (how many) Display the number of integers > 0   (how many) Display the number of integers < 0   (how many) Display the...

  • In Java create an integer array named dice1 with a size of 10. Populate each array...

    In Java create an integer array named dice1 with a size of 10. Populate each array location with a roll of a six-sided die (hint: an int value of 1 through 6). Print the array out using an enhanced for loop. Sample output: Question 1 dice1 = 1 1 6 2 3 5 1 5 4 5

  • in java / You will: // 1- create a square 2 dimensional array of random size...

    in java / You will: // 1- create a square 2 dimensional array of random size (less than 11) // 2- fill the array with random integers from 1 to the size limit // 3- print the array // 4- prompt to see if the user wants to do another //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // 1- The square can use the same random value for x and y. Don't allow 0 size arrays. // 2- Maybe a nested set of for loops? to...

  • Be sure to include the number of total swaps in each sort. Create a total_Time variable...

    Be sure to include the number of total swaps in each sort. Create a total_Time variable is the total time it takes all 1000 iterations to run. DO NOT INCLUE THE TIME IT TAKES TO GENERATE A UNIQUE RANDOM ARRAY EACH LOOP. In java, Write a computer program that prompts the user for one number, n for the number of items in the array to sort and create and sort 1000 different arrays of this size,  timing the run to get...

  • C++: Create a class called "HashTable" This class will implement hashing on an array of integers...

    C++: Create a class called "HashTable" This class will implement hashing on an array of integers Make the table size 11 Implement with linear probing. The hash function should be: h(x) = x % 11 Create search(), insert() and delete() member functions. Search should return the index of where the target is located, insert should allow the user to insert a value, and delete removes the desired value from the table. In main perform the following: 1. Insert: 17 11...

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