1.I want to print out the animals names and what the user inputs at the end of the program that can fit in a spreadsheet. e.g. 500, panthers.
import java.util.Scanner;//import scanner so user can input
class arrays {
public static void main(String[] param){
String[] animals = arrays(); // creating string array to store information
forloop(animals);// passing the array to the method forloop
System.exit(0);
} //end main method
public static String[] arrays() {
String[] animals = new String[5]; //array to store 5 animals
animals[0] = "Dragon"; //animals stored
animals[1] = "Bee";
animals[2] = "Poon";
animals[3] = " Panther";
animals[4] = "White Ants";
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.
{
String ans;
System.out.println(animals[i] + ":");
System.out.println("How many are left?"); // prints the question
Scanner scanner = new Scanner(System.in); // allows the user to input
ans = scanner.nextLine();
2.if statement used to print out the smallest number types by the user. How do I do this? I want to use the
if(ans<=20) {
System.out.println("The most dangerous animal is the " + animals[i] + "."); // prints out the most dangerous animal
System.out.println("There are only 10 left.");
}
}
}
}
Aucun commentaire:
Enregistrer un commentaire