So here I am again with another problem. You'll understand what i mean as soon as you read my code and output. I'm trying to print my Array's numbers and their occurrences. !!!I can't use any of import codes unfortunately...!!!
int[] fr = new int[Bag.length];
for( int i = 0; i < Bag.length; i++ )
fr[i]++;
for( int i = 0; i < fr.length; i++ ) {
if( fr[i] > 0 )
System.out.println( "The number " + Bag[i] + " occurs " + fr[i] + " time(s).");}}
If i add 5, 6 and 5 to my array; ( I created my Add operation btw so at first my array is 0 and then getting bigger )
Output : The number 5 occurs 1 time(s). The number 6 occurs 1 time(s). The number 5 occurs 1 time(s).
My Add operation btw is :
int[] Bag = new int[0];
String name = scanner.next();
if (name.equals("A")){
int number = scanner.nextInt();
NewBag[NewBag.length - 1] = number;
for(int i = 0; i < Bag.length; i++){
NewBag[i] = Bag[i];}
Bag = NewBag;
System.out.println(number + " added to Bag.");}