I'm working with eclipse and when I want the program to print either all the array elements or just a single array element via indexing. It doesn't return an error or even an address when I run the program.
import java.util.Scanner;
public class FavoriteListMaker {
public static void main(String[] args)
{
Scanner inputDevice = new Scanner(System.in);
System.out.println("This program is to help you order a favorites list. Please enter the amount of items on the list.");
int ListSize = inputDevice.nextInt();
String [] TopXA = new String [ListSize + 1];
int [] TopXB = new int[ListSize + 1];
for (int x = 0; x < TopXA.length; ++ x)
{
System.out.println("Please enter an item to be organized on the list");
String item = inputDevice.nextLine();
TopXA[x] = item;
System.out.println("You have " + (ListSize - x) + " items left to fill on the list.");
}
System.out.println("Now we will compare each item on the list with every item on the list one at a time.");
System.out.println("We will ask you a series a question on whether you like item A better then item B and tally the score.");
System.out.println("At the end the item with the most points wins.");
for (int y = 0; y < TopXA.length; ++ y)
for (int z = 0; z < TopXA.length; ++ z)
{
String compareA = TopXA[y];
String compareB = TopXA[z];
System.out.println("Do you prefer " + compareA + " or " + compareB + " .");
System.out.println("If you prefer " + compareA + "Please press 1. If you prefer " + compareB + " please press 2.");
int choice = inputDevice.nextInt();
switch(choice)
{
case 1:
TopXB[y] =+ 1;
break;
case 2:
TopXB[z] =+ 2;
break;
default:
System.out.print("I'm sorry but that is not a valid input.");
}
}
When I run the code it will print out. "Do you prefer or ." instead of the array element.