-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJavaArray06.txt
More file actions
35 lines (31 loc) · 1.14 KB
/
JavaArray06.txt
File metadata and controls
35 lines (31 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/*Write a Java program that will take an integer number N from the user and create an integer array by taking N numbers from the user. Print how many times each number appears in the array.
Sample Input Sample Output
N=5
6 6 - 2 times
15 15 - 2 times
14 14 - 1 times
15
6
*/
import java.util.Scanner;
public class Task06{
public static void main(String [] args){
Scanner sc= new Scanner(System.in);
int n=sc.nextInt();
int[]arr= new int[n];
for(int i=0;i<n;i++){
arr[i]=sc.nextInt();}
for(int i=0;i<n;i++){
int count=0;
boolean flag= false;
for(int k=0;k<i;k++){
if(arr[i]==arr[k]){
flag=true;
break;}}
if(!flag){
for(int j=0;j<n;j++){
if(arr[i]==arr[j] && i<=j){
count++;}}
System.out.println(arr[i] + " - " + count +" times");}}
}
}