In: Computer Science
Source Code:
Output:
Code in text format (See above image of code for indentation):
import java.util.*;
/*class definition*/
public class LastnameFirstname09
{
/*main method*/
public static void main(String[] args)
{
/*Scanner object to read data from the user*/
Scanner in=new Scanner(System.in);
/*array declaration*/
String[] myFavoriteSnacks=new String[10];
/*read item names from user and store in array using loop*/
System.out.println("Enter 10 items in one of your favorite foods/snacks:");
for(int i=0;i<10;i++)
myFavoriteSnacks[i]=in.nextLine();
/*print contents of the array*/
System.out.println("Your favourite foods/snacks");
System.out.println("-------------------------------------");
for(int i=0;i<10;i++)
System.out.println(i+1+"\t"+myFavoriteSnacks[i]);
}
}