Creating a new array based on the existing one


Joined
Nov 6, 2020
Messages
3
Reaction score
0
correct my code please.
I`m need to create new array without minimum vulue.


Java:
public class ArT {
    public static void main(String[] args) {

        int min;
        int[] arrayA;
        int size;
        int newSize;
        int counter;

        min = 50;
        arrayA = new Random().ints(50, 0, 50).toArray();
        size = arrayA.length;
        counter = 0;

        System.out.println("my array: " + Arrays.toString(arrayA));

        for (int i : arrayA) {
            if (i <= min) {
                min = i;
            }
        }

        System.out.println("min: " + min);

        for (int i : arrayA) {
            if (min == i) {
                counter++;
            }
        }

        System.out.println("min counter: " + counter);

        newSize = size - counter;

        int[] arrayB;
        arrayB = new int[newSize];

        for (int j = 0; j < arrayA.length; j++) {
            for (int k = 0; k < arrayB.length; k++) {

                if (arrayA[j] != min) {
                    arrayB[k] = arrayA[j];
                } else {
                    j++;
                }
            }
        }

                System.out.println("new array: " + Arrays.toString(arrayB));

        }
    }
 
Ad

Advertisements

Joined
Nov 6, 2020
Messages
3
Reaction score
0
Dear administrators, is the question asked yesterday 10pm still relevant today 10pm?
your checks destroy the forum.
strange that he is still alive.
 
Joined
Apr 25, 2017
Messages
170
Reaction score
23
Hi, what you mean by "create new array without minimum vulue" ?
What is your current output and expected output?
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top