Skip to content

Commit a4257b5

Browse files
authored
Add files via upload
1 parent 53f5090 commit a4257b5

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

JavaArray06.txt

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*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.
2+
3+
Sample Input Sample Output
4+
N=5
5+
6 6 - 2 times
6+
15 15 - 2 times
7+
14 14 - 1 times
8+
15
9+
6
10+
*/
11+
12+
import java.util.Scanner;
13+
public class Task06{
14+
public static void main(String [] args){
15+
Scanner sc= new Scanner(System.in);
16+
int n=sc.nextInt();
17+
int[]arr= new int[n];
18+
for(int i=0;i<n;i++){
19+
arr[i]=sc.nextInt();}
20+
for(int i=0;i<n;i++){
21+
int count=0;
22+
boolean flag= false;
23+
for(int k=0;k<i;k++){
24+
if(arr[i]==arr[k]){
25+
flag=true;
26+
break;}}
27+
if(!flag){
28+
for(int j=0;j<n;j++){
29+
if(arr[i]==arr[j] && i<=j){
30+
count++;}}
31+
System.out.println(arr[i] + " - " + count +" times");}}
32+
}
33+
}
34+
35+

0 commit comments

Comments
 (0)