You never call your method “forloop()”, that’s the reason why there’s nothing printed.
NewbieJavaDeveloper’s answer is a good one. But if you want to pactice “method and return”, here is another answer:
import java.util.Scanner;//import scanner so user can input
class arrays
{
public static void main(String[] param)
{
String[] animals = arrays();
forloop(animals);
System.exit(0);
} //end main method
public static String[] arrays() //array method
{
String[] animals = new String[5]; //array to store 5 animals
animals[0] = "Komodo Dragon"; //animals stored
animals[1] = "Manatee";
animals[2] = "Kakapo";
animals[3] = "Florida Panther";
animals[4] = "White Rhino";
return animals;
}
public static void forloop(String[] animals)
{
for(int i =0; i<5; i++) //for loop to print the below
//print 5 times using the different animal names.
{
System.out.println(animals[i] + ": How many are left in the wild?");
}
}
}
I made minimun change to your code, hope you can find it easy to understand.
solved When I compile this why doesn’t it print anything? [closed]