You are comparing the input string (which contains a newline character) with a single character, so both your if statements will fail. You should do something like:
String yeasNo = sc.next();
if(yeasNo.substring(0,1).equals("y")) {
addFood(i);
}
else if(yeasNo.substring(0,1).equals("n")) {
System.out.println("Nothing");
}
else {
System.out.println("Bad input");
}
However, you still have the problem that after calling
addFood
your program will terminate. And even if you fix that, every time you call
addFood
it creates a new array of
Food
objects, but then when the method returns that array is disposed so it no longer exists.
You obviously need more Java study, and I recommend spending time going through
The Java™ Tutorials[
^].