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.
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
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.