Hi everyone,
I want to input and store some values in arrays but when I compile and execute it, the command line shows :
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
This is my code :
It means while you are running your program, java is not able to find class file in classpath. Make sure you are properly setting the classpath while running like :
Thanks everyone, I found the solution to my problem
But I have another problem which comes when I run the code. I want to inout the values t the array when the code comes but this is the output that comes:
When you call scanner.nextInt(), it doesn't remove the line break from the Scanner. That's why you aren't asked to fill in anything for "Enter name 2" and the "Enter weight 2" prompt immediately shows. The line break you entered for the 1st weight is what is returned by the call to nextLine() on line 10. If you put a scanner.nextLine(); after line 12 you will consume that line break. You'd have to check what else it consumes though. If I enter "15 abc", the "abc" part is ignored now.
Jain Pratik wrote:Issue is with scanner.nextInt(); , if you want scanner to wait for the line always used scanner.nextLine().
so replace line 12 with
Rob Spoor wrote:When you call scanner.nextInt(), it doesn't remove the line break from the Scanner. That's why you aren't asked to fill in anything for "Enter name 2" and the "Enter weight 2" prompt immediately shows. The line break you entered for the 1st weight is what is returned by the call to nextLine() on line 10. If you put a scanner.nextLine(); after line 12 you will consume that line break. You'd have to check what else it consumes though. If I enter "15 abc", the "abc" part is ignored now.
Thanks a lot guys, I got the whole program correct. It works perfectly now.