0

I am trying to run the following code in order to input an array of any size I desire:

import java.util.Scanner;
import java.util.Arrays;

public class testing2 {

    public static void main(String[] args) {
        
        double[] inputs = new double[5];
        int currentSize = 0;
        
        System.out.println("Please enter values, Q to quit:");
        Scanner in = new Scanner(System.in);
        
        while (in.hasNextDouble())
        { 
           if (currentSize >= inputs.length)
           {
              inputs = Arrays.copyOf(inputs, 2 * inputs.length);
           }
          
           inputs[currentSize] = in.nextDouble();
           currentSize++;
        }
        inputs = Arrays.copyOf(inputs, currentSize);
        
        System.out.print(inputs);

    }

}

But when I input any array, my output is just a combination of symbols such as: [D@13fee20c, and this is not the output I am hoping for. Could anyone help me?

  • [What's the simplest way to print a Java array?](https://stackoverflow.com/questions/409784/whats-the-simplest-way-to-print-a-java-array) –  Mar 30 '21 at 21:11
  • 2
    Does this answer your question? [What's the simplest way to print a Java array?](https://stackoverflow.com/questions/409784/whats-the-simplest-way-to-print-a-java-array) – Henry Twist Mar 30 '21 at 21:12

1 Answers1

0

You're not printing correctly:

        for (int i = 0; i < input.length; i++)
            System.out.print(input[i] + " ");
    }
I M
  • 313
  • 1
  • 9