• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Confused with output of program using Scanner class

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

and the file "Donnie" is


Donnie Darko/sci-fi/Gyllenhall, jake
Raiders of the Lost Ark/action/Ford,Harrison
2001/ sci-fi/hello
Caddy Shack/comedy/Murray, Bill
Star Wars/sci-fi/Ford, Harrison


output is

Donnie Darko/sci-fi/Gyllenhall, jake
Raiders of the Lost Ark/action/Ford,Harrison
2001/ sci-fi/hello
Caddy Shack/comedy/Murray, Bill
Star Wars


why not /sci-fi/Ford, Harrison is in the output i am so confused
 
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Rajat welcome to JavaRanch.

Are you sure that is the output as in your DvdInfo class each field's value is separated by -- but in your output its separated by /
 
Rajat kumar jain
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
oh no sorry ankit sir its
[Donnie Darko--sci-fi--Gyllenhall, jake
Raiders of the Lost Ark--action-Ford,Harrison
2001-- sci-fi--hello
Caddy Shack--comedy--Murray, Bill
Star Wars]
 
Ranch Hand
Posts: 430
Android VI Editor Debian
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Inside your while loop you are only populating one of the fields on each iteration. This means that hasNext() will return false before you completed populating your fields. You want to populate all your fields for each record on each iteration and therefore you need to increment "i" every time you issue sc.next();








 
Rajat kumar jain
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
first of all thank you O.Ziggy for reply,but sir my requirement is not that you have posted. i want to have an output like this



Donnie Darko--sci-fi--Gyllenhall, jake
Raiders of the Lost Ark--action--Ford,Harrison
2001-- sci-fi--hello
Caddy Shack--comedy--Murray, Bill
Star Wars--sci-fi--Ford, Harrison
 
Your mind is under my control .... your will is now mine .... read this tiny ad
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic