0

I have this code:

String str;
Scanner Lectura = new Scanner(System.in);
System.out.print("Type a word in plain form: ");
str=Lectura.next();
//obtains word
String substring = str.length() > 2 ? str.substring(str.length() - 2) : str;
System.out.print(substring);

...to get the last two digits of a word. I intent to use it with japanese verbs, but for some reason it just returns question marks:

https://i.stack.imgur.com/3e7C2.png

I typed in 食べる which should return べる; the last two characters. Here's proof it's not a unicode problem or something (the console font is so small):

https://i.stack.imgur.com/dTHEz.png

What's the problem? What can I do to get those characters and not question marks?

1 Answers1

0

I guess the Scanner is using your system's default encoding? Your sample works for me (I have UTF-8 on my OS...) You can specify the encoding when creating Scanner, maybe it will help?

Scanner Lectura = new Scanner(System.in, "UTF-8");
ladar
  • 5,858
  • 3
  • 26
  • 38
  • Well the project's encoding is UTF-8, and I even tried changing the font to Arial Unicode MS, but it didn't do anything. I tried what you suggested but it didn't change either: http://imgur.com/97FjgDS . I have Windows 7 and judging from this post: http://superuser.com/questions/239810/setting-utf8-as-default-character-encoding-in-windows-7 you can't get UTF-8 in Windows 7. Does that mean there's no hope? The system encoding must be the problem. – Rain Awareness Feb 24 '17 at 04:07
  • Have you tried this http://stackoverflow.com/a/24784421/475726 ? Maybe it is just problem of NetBeans. Have you tried your app from command line? – ladar Feb 24 '17 at 06:32
  • My code doesn't give me that yellow light bulb suggestion, and I frankly don't know what "Go to etc folder in Netbeans home" even means, or what "trying from command line" means either, I open command line and it doesn't let me type anything at all. I don't know much about programming; I was just trying to learn Java to make a Japanese conjugation practice tool because it is sorely needed, but if just the first step is so obscure, mysterious and hard to do I think I give up. Thanks for your help though. – Rain Awareness Feb 26 '17 at 04:07