У меня есть следующий код, который должен взять у пользователя 10 символов и распечатать их в обратном порядке. Кажется, я не могу пройти эту синтаксическую ошибку для Scanner
. Как я могу ввести один символ за раз? Вот то, что я до сих пор:Чтение Char Into Array
import java.util.Scanner;
public class ReverseOrder
{
//-----------------------------------------------------------------
// Reads a list of char from user and prints in reverse.
//-----------------------------------------------------------------
public static void main (String[] args)
{
Scanner scan = new Scanner (System.in);
char[] letters = new char[10];
System.out.println ("The size of the array: " + letters.length);
for (int index = 0; index < letters.length; index++)
{
System.out.print ("Enter number " + (index+1) + ": ");
letters[index] = scan.nextchar(); //doesnt like this line
}
System.out.println ("The numbers in reverse order:");
for (int index = letters.length-1; index >= 0; index--)
System.out.print (letters[index] + " ");
}
}
Также см http://stackoverflow.com/questions/18746185/why-doesnt-the-scanner-class-have -a-nextchar-method и http://stackoverflow.com/questions/2597841/scanner-method-to-get-a-char и http://stackoverflow.com/questions/19417813/compiler-says-java-code -is-invalid/19417824 # 19417824 – Justin