How to convert Scanner to double in java?

Asked

Viewed 166 times

-2

I am developing a software, in which at a moment the system must take a value informed by the user using the Scanner class and insert it into an array and then return an array with the values typed by the user, but I can’t do the Scanner to double conversion. Follow the line of code:

  double[] a = [Double.parseDouble(vlrus.nextDouble() + "")];
  • From Scanner to Double? wouldn’t be from Double to Int?

  • Could be, why the exercise did not make it clear that it would be a specific type.

  • I was confused because Scanner is a function, not a primitive type

1 answer

1

I see no reason for you to try using an array here. I think what you want is just this:

double a = vlrus.nextDouble();

Then store the result in the array:

double[] b = new double[] {a};
  • In the question is asked to read data from the keyboard and store them in an array

  • @Then edit the question making clear what you need. Your question spoke nothing of arrays. I edited the answer to show how to create an array with the value read.

  • Okay, thank you very much.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.