• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Junilu Lacar
  • Martin Vashko
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Scott Selikoff
  • salvin francis
  • Piet Souris

How read data from scanner into alternate int arrays?

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I have to create a method:



It should read values from the input line alternately into xVal and yVal until a negative value is read or until greater than 2∗maxPoints
are read. which returns an int numPoints.
output needs to be shown in the format:


Having trouble figuring out how to read into ALTERNATE arrays. Thank you
 
Carey Brown
Saloon Keeper
Posts: 6469
61
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is an improper call to println() which only takes one argument, but you've given it two. I'm guessing you mean:
 
Marshal
Posts: 66637
251
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Parallel arrays? Loading the arrays via a static method? Both those things look like iffy design to me. Who told you to use that sort of design?
I would give such a method void instead of a return type. And why do you need a parameter for number of points? Can't you get that from the two arrays? Throw an exception if the two arrays aren't the same size.
It is easy enough to get a double from a Scanner with its nextDouble() method, but make sure you only write numbers. Maybe you could display this sort of thing:-

Next 2 numbers please: 123.45 234.56
Next 2 numbers please: 345.67 456.78
Finished

 
The moustache of a titan! The ad of a flea:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!