*
The moose likes Beginning Java and the fly likes what is the error in this program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "what is the error in this program" Watch "what is the error in this program" New topic
Author

what is the error in this program

s john smith
Greenhorn

Joined: Jan 12, 2012
Posts: 16

this is the question-Write a class for Employee. Variables contained in the class are id, name and department. Create 10 objects for Employee class and store them in the array. While creating the object, values for the variables are obtained as input from the user. Iterate the array and print the details of the employee.

and my program is


i couldn't able to enter the values for name. this is my output


Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38040
    
  22
The nextLine() method of Scanner doesn’t do what you think it does. Some books are unclear about it; in fact I use it as a test when reviewing a book: have they got nextLine() wrong?
The API is correct, but not easy to understand, so ignore the rants in this post, and see how nextLine works.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38040
    
  22
By the way: why are you using a List when the question clearly says “array”?
s john smith
Greenhorn

Joined: Jan 12, 2012
Posts: 16

thanks a lot. i corrected my code. is this correct?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38040
    
  22
If I enter
123456 Campbell Ritchie FMPRG
. . . as one line, what will happen?

Do you think it is correct code? Or what do you think is wrong with it?
s john smith
Greenhorn

Joined: Jan 12, 2012
Posts: 16

no i cant enter it in a line. i should enter the values line by line. but is there any way to type it in a single line
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38040
    
  22
You could have done it with a Scanner. Only you would have to find some way to join the two halves of the name. Or have firstName and lastName fields in the Employee class.
Did you follow the links I provided yesterday? I think they would have sorted out your problem.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: what is the error in this program
 
Similar Threads
Using using an enhanced for loop
Code problems
Circular List
Identifier expected
try...catch blocks giving <identifier> expected error