Question

In: Computer Science

Given an array of integers, delete each element from the array which is a multiple of 5, and display the rest of the array.


Given an array of integers, delete each element from the array which is a multiple of 5, and display the rest of the array.

Input:

    6

    2 3 4 11 22 320

    where:

  • First line represents the number of elements in the array.

  • Second line represents the elements in the array.

Output:

    2 3 4 11 22

Explanation: Element of the array 320 is the only one in the array which is a multiple of 5, so it is removed from the array.

Assumptions:

  • Array can be of size from 1 to 1000.

  • Array element can be in the range -1000 to 1000

Solutions

Expert Solution

Java Program to Delete element(s) which is multiple of 5 from an integer array.

Main.java :

import java.util.Scanner; // importing Scanner class to get keyboard inputs.
public class Main {
        
        // main method
        public static void main(String args[]) {
                
                // Creating Scanner object named keyboard to get keyboard input.
                Scanner keyboard = new Scanner(System.in);
                // Prompt for array size and store input in int variable arraySize.
                System.out.print("Enter size of array: ");
                int arraySize = keyboard.nextInt();
                
                int array[] = new int[arraySize]; // creating int array of      size arraySize (provided via input.)
                int multipleCount =0; // multipleCount variable hold count of total element which is multiple of 5.
                
                
                // Prompt for array element and insert each input value in array.
                System.out.print("Enter size of array: ");
                /*
                below for loop will execute arraySize times (for example if arraySize = 5 then loop will execute 5 times)
                */
                for(int i=0;i

Smple Output :

Please refer to the Screenshot of the code given below to understand indentation of the code.


Related Solutions

Given an array of integers and the size of the array, write a function findDuplicate which prints the duplicate element from the array.
C++ Programming using iostream and namespace stdGiven an array of integers and the size of the array, write a function findDuplicate which prints the duplicate element from the array. The array consists of all distinct integers except one which is repeated. Find and print the repeated number. If no duplicate is found, the function should print -1. void findDuplicate (int [ ], int)Example 1: Given array: {2,3,5,6,11,20,4,8,4,9} Output: 4 Example 2: Given array: {1,3,5,6,7,8,2,9} Output: -1
Part 1- Delete an element from an Array. See the instructions below: -Use the previous Array...
Part 1- Delete an element from an Array. See the instructions below: -Use the previous Array code provided to you (to demonstrate how to insert elements in an Array). It is an Array with the following details: Size 10 Length 5. Your task is to Delete element on index 4 please use the code below and write in C++ how to delete the 4th element. #include struct Array { int A[10]; int size; int length; }; void Display(struct Array arr)...
5. Suppose you are given an n-element array containing distinct integers that are listed in increasing...
5. Suppose you are given an n-element array containing distinct integers that are listed in increasing order. Given a number k, describe a recursive algorithm to find two integers in A that sum to k, if such a pair exists. What is the running time of your algorithm? Java Language....
Input: An array of non-negative integers, where each element in the array represents your maximum jump...
Input: An array of non-negative integers, where each element in the array represents your maximum jump length at that position. Output: A boolean value if you are able to reach the last index starting if you start at the first spot in the array. [Please write a recursion function!] Example 1: Input: [2,4,1,2,4,1] Output: True (Ex. 0 to 1 to 5 or 0 to 2 to 3 to 5) Example 2: Input: [3,2,1,0,4] Output: false (You will always arrive at,...
Given an array, return the element at which the "pattern" breaks. For example, in the array...
Given an array, return the element at which the "pattern" breaks. For example, in the array [2,4,6,8,11,13,15,17], the algorithm should return 11 because the difference between every previous node was 2, and the difference between 8 and 11 is 3. PLEASE USE DIVIDE AND CONQUER. Thank you. Python please or just a description of the algorithm
Suppose you are given an n-element array containing distinct integers that are listed in increasing order....
Suppose you are given an n-element array containing distinct integers that are listed in increasing order. Given a number k, describe a recursive algorithm to find two integers in A that sum to k, if such a pair exists. What is the running time of your algorithm?
How would you take a given array of non-repeating random integers and sort every 5th element. Meaning index 0 is the smallest element in the array.
JAVA ProgrammingHow would you take a given array of non-repeating random integers and sort every 5th element. Meaning index 0 is the smallest element in the array. index 4 is the 5th smallest element in the array, index 9 is the 10th smallest element in the array and so on...- this array could be small (like 5 indexes) or large (like 100,000 indexes).- all other numbers do not change position
php please // 5) isArraySorted // Given an array , return true if the element are...
php please // 5) isArraySorted // Given an array , return true if the element are in ascending order. // Note: 'abe' < 'ben' and 5 > 3 // Precondition $arr has all the same type of elements function isArraySorted($arr) {    } echo PHP_EOL . 'isArraySorted(array(1, 2, 2, 99) 1: ' . isArraySorted ( array ( 1, 2, 2, 99 ) ) . "\n"; assert ( isArraySorted ( array ( 1, 2, 2, 99 ) ) ); echo 'isArraySorted(array(2,...
Write a program to remove an element from an array at the given position k and...
Write a program to remove an element from an array at the given position k and push the rest of the array elements one position back. Then insert the removed element at the beginning. Position k is entered through keyboard. For example, if the original array x is {'r', 'c', 'm', '7', 'w', '3', 'q'} and k = 3, the array will be changed to {'7', 'r', 'c', 'm', 'w', '3', 'q'}. Hint: Sequence of moving the element is important....
Creates a 100-element array, either statically or dynamically Fills the array with random integers between 1...
Creates a 100-element array, either statically or dynamically Fills the array with random integers between 1 and 100 inclusive Then, creates two more 100-element arrays, one holding odd values and the other holding even values. Prints both of the new arrays to the console. In C++. Thank you!
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT