• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

How read data from scanner into alternate int arrays?

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Saloon Keeper
Posts: 9562
79
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
 
Carey Brown
Saloon Keeper
Posts: 9562
79
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 76446
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
Getting married means "We're in love, so let's tell the police!" - and invite this tiny ad to the wedding:
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic