Concept explainers
(The Sieve of Eratosthenes) A prime integer is any integer greater than 1 that can be divided evenly only by itself and 1. The Sieve of Eratosthenes is a method of finding prime numbers. It works as follows:
- Create an array with all elements initialized to 1 (true). Array elements with prime indices will remain 1. All other array elements will eventually be set to zero.
- Starting with array index 2 (index 1 is not prime), every time an array element is found whose value is 1, loop through the remainder of the array and set to zero every element whose index is a multiple of the index for the element with value 1. For array index 2, all elements beyond 2 in the array that are multiples of 2 will be set to zero (indices 4, 6, 8, 10, and so on.). For array index 3, all elements beyond 3 in the array that are multiples of 3 will be set to zero (indices 6, 9, 12, 15, and so on.).
When this process is complete, the array elements that are still set to 1 indicate that the index is a prime number. Write a
Trending nowThis is a popular solution!
Chapter 6 Solutions
C How to Program (8th Edition)
Additional Engineering Textbook Solutions
Starting Out with Java: From Control Structures through Objects (6th Edition)
Starting out with Visual C# (4th Edition)
Starting Out with Programming Logic and Design (4th Edition)
Starting Out With Visual Basic (8th Edition)
Java How to Program, Early Objects (11th Edition) (Deitel: How to Program)
Starting Out with C++ from Control Structures to Objects (8th Edition)
- Method Details: public static void rotate(int[] array, boolean leftRotation, int positions) Rotates the provided array left if leftRotation is true; right otherwise. The number of positions to rotate is determined by positions. For example, rotating the array 10, 20, 7, 8 two positions to the left will update the array to 7, 8, 10, 20. Only arrays with 2 or more elements will be rotated. Hint: adding private methods that rotate an array one position to the left and one position to the right can help. Parameters: array - leftRotation - positions - Throws:java.lang.IllegalArgumentException - When a null array parameter is providedarrow_forward(Two dice are rolled 100 times (you can do this with two random values from 1 to 6 in your program). After rounding 100 times, keep the iteration value of how many times each state occurs in a two-dimensional array. For example, the index number of [1,1] must follow the number of times the dice rolls 1 to 1).arrow_forward(Intro to Java) Explain the answers to the below questions. include a written answer to the question using step-by-step explanation 4. Write the linearSearch method as follows using the algorithm provided in class: The method is named linearSearch It takes on array of doubles as a parameter It takes a double value to locate in the array as a second parameter It returns the integer location (index) in the array where the value is located Or, it returns -1 if the value cannot be foundarrow_forward
- Question 3 : (Eliminate duplicates) Write a program Duplicate.java that reads in ten integers in an array T, creates a new array V by eliminating the duplicate values in the array, and displays the result. Here is the sample run of the program: Enter ten numbers: 1 2 3 2 1 6 3 4 5 2 The distinct numbers are: 1 2 3 6 4 5arrow_forwardJava Programming [ Using Array] - 1arrow_forwardCorrect the following wrong statements. Each row in a single dimensional array could be dealt with as 2-dimensional array.arrow_forward
- (Java in eclipse).arrow_forwardDeclare an array to hold the tax for up to 10 different sales.arrow_forward1.Answer the following questions: 1(a) Write a method to compute and return the value of maxEven and minOdd where maxEven is the largest even element of an int array and minOdd is the smallest odd element of the int array. The method is passed the int array and an int value that denotes the number of elements in the array. You may assume that the int array has at least 1 element in it. 1(b) Write a method to compute and return the value of countEven and countOdd where countEven is the number even elements in an int array and countOdd is the number of odd elements in the int array. The method is passed the int array and an int value that denotes the number of elements in the array. You may assume that the int array has at least 1 element in it.arrow_forward
- (Locate the largest element) Write the following function that finds the location of the largest element in a two-dimensional array. void 1ocateLargest(const double a[][4 ], int 1ocation[]) The location is stored in a one-dimensional array location that contains two elements. These two elements indicate the row and column indices of the largest element in the two-dimensional array. Write a test program that prompts the user to enter a 3 × 4 two-dimensional array and displays the location of the largest element in the array.arrow_forwardIs there a way to increase the size of an array after its declaration?arrow_forwardUsing methods and arrays, write a program that Creates and fills an array A of size 100 filled with random integers in the range 1 to 100 inclusive. prints it out in 5 lines (20 values per line). Calculates the sum of the even elements of A and print it out.arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education