Discard Specific Content in java
For this challenge, you will be given an array and you are
* asked to find multiples of 5 and 10 both in the given array,
* remove them from the array. Rest all the elements will
* preserve their orders.
*
* Input Format - you will be taking a number as an input from
* stdin which tells about the length of the array. On another line,
* array elements should be there with single space between them.
* Output Format - print the required array to the stdout.
Sample Test Case:
Sample Input:-
7
10 20 15 2 4 7 8
Sample Output -
15 2 4 7 8
* asked to find multiples of 5 and 10 both in the given array,
* remove them from the array. Rest all the elements will
* preserve their orders.
*
* Input Format - you will be taking a number as an input from
* stdin which tells about the length of the array. On another line,
* array elements should be there with single space between them.
* Output Format - print the required array to the stdout.
Sample Test Case:
Sample Input:-
7
10 20 15 2 4 7 8
Sample Output -
15 2 4 7 8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
public class DiscardSpecficContent { | |
public static void main(String[] args) { | |
Scanner sc=new Scanner(System.in); | |
int size; | |
size=sc.nextInt(); | |
int [] arr=new int[size]; | |
for(int i=0;i<size;i++){ | |
arr[i]=sc.nextInt(); | |
} | |
for(int j=0;j<arr.length;j++){ | |
if(arr[j]%5!=0||arr[j]%10!=0){ | |
System.out.print(arr[j]+" "); | |
} | |
} | |
sc.close(); | |
} | |
} |
Input:
7
10 20 15 2 4 7 8
Output:
15 2 4 7 8
7
10 20 15 2 4 7 8
Output:
15 2 4 7 8
Comments
Post a Comment