You are reading number of persons 10
but you are handling only 9
of them. Problem is your for loop. You are iterating from 1
till 9
(9 is last number <10
).
You should start iterating from 0
so change
for(int o = 1; o<np; o++)
to
for(int o = 0; o<np; o++)
Otherwise you will be reading 9
persons so you will handle only
mitnik
Poulsen
Tanner
Stallman
Ritchie
Baran
Spafford
Farmer
which will leave
Linus
mitnik
300 3
Poulsen
Tanner
Baran
Poulsen
1000 1
Tanner
.
.
.
so in your next loop
String person = scan.next();
int amount = scan.nextInt();
int giveto = scan.nextInt();
String person = scan.next();
will return Linus
, but int amount = scan.nextInt();
will try to parse mitnik
which is not integer which will throw InputMismatchException
.