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));

        }
    }
 
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
260
Reaction score
36
Hi, what you mean by "create new array without minimum vulue" ?
What is your current output and expected output?
 

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

Members online

Forum statistics

Threads
474,057
Messages
2,570,443
Members
47,113
Latest member
XZJMike318

Latest Threads

Top