0

I'm trying this:

Scanner keyboard = new Scanner(System.in);
char[] character = keyboard.next().toCharArray();
while (character.length != 5) {
     keyboard = new Scanner(System.in);
     character = keyboard.next().toCharArray();
}

Until you introduce 5 character keeps asking you to introduce the 5 characters again but when i try to introduce the special characters 'ñ' or 'ç' it doesn't work, i have tried it without the while to print the results and the only thing that prints are squares . How could this be solved?

I'm using NetBeans IDE 7.4.

By it doesn't work I mean I just keep asking to introduce more characters and it is just stuck until you introduce 5 normal characters.

Luiggi Mendoza
  • 85,076
  • 16
  • 154
  • 332
tmg
  • 1
  • 1

2 Answers2

1

Use in both cases the encoding of your operating system.

String encoding = "Cp1252"; // Western Latin-1
Scanner keyboard = new Scanner(System.in, encoding); // Twice!

If you print the default encoding:

System.out.println(System.getProperty("file.encoding"));

You will probably see, that the IDE uses "UTF-8" or so. That is, it has changed file.encoding. System.in and System.out however need to use just the original encoding.

Joop Eggen
  • 107,315
  • 7
  • 83
  • 138
1

You might want to check this answer.

Edit the netbeans.conf in the etc folder of NetBean and add -J-Dfile.encoding=UTF-8 to netbeans_default_options. Then restart.

Community
  • 1
  • 1
ortis
  • 2,203
  • 2
  • 15
  • 18