Take the 2-minute tour ×

So. I'm wondering how could i make it so that

  1. System prints word which contains a-z + å, ä and ö letters. (At the moment å, ä and ö are printed in a weird way. I'm pretty sure that you know what it looks like :D)
  2. User inputs a word and compares it to the first word. And at the moment if the word above ^ contains ä, ö or å and i input that word.. It won't see the match between those 2..

So the question is: How can I make it so that if you put å, ä or ö to input it will notice that it's exactly the same å, ä, ö in the word it just printed? I'm using


There's my whole code :D Mostly just quests and answers :)

import java.io.*;
import java.awt.*;
public class sanaopisto {
public static int quanity;
public static String rightanswer;
public static String question;
public static int right;
public static int wrong;
public static double ratio;
public static void main(String[] args) {
System.out.print("Moneenko sanaan tahdot vastata? ");
quanity = Integer.parseInt(in.readLine());
for(int x=0; x<quanity; x++){
System.out.println(x+1 +". kysymys");
System.out.println("Oikeita vastauksia " +right +" ja v\u201e\u201eri\u201e " +wrong +".");
}catch(Exception e) {
        System.out.println("Tapahtui virhe.");}}
 public static void getquestion(int quanity) {
 int[] done = new int[100];//create array but everything is null
for(int i = 0; i<done.length; i++)
done[i] = 0;//need default values else wise it'll just be NULL!!!
//must be done before the do-while loop starts
 boolean allDone = false;
 String answer;
 int ran;
if (!areAllQuestionsComplete(done)){ //Changed (!areAllQuestionsComplete(done)) thingy like this..
do{ //And made this work properly etc.
ran = (int)(Math.random() * 53 + 1);
} while (done[ran] == 1);

if(done[ran] != 1)
    //ask random question
    //if answer is correct, set done[ran] = 1
    //else just let do-while loop run
    if (ran == 1) { //1
    question = "ruotsalainen";
    rightanswer = "svensk, -t, -a";}
    if (ran == 2) { //2
    question = "suomalainen";
    rightanswer = "finländsk, -t, -a";}
    //. Took some code away from here.. Because too many questions.. In real version I have all the 1-84 questions :D
    if (ran == 83) { //15
    question = "globalisoitunut";
    rightanswer = "globaliserad, -at, -ade";}
    if (ran == 84) { //15
    question = "maailma";
    rightanswer = "en värld, -en, -ar, -arna";}
    System.out.print("Vastaus?: ");
    answer = in.readLine();
    if (answer.equals(rightanswer)){           
    done[ran] = 1;}
    System.out.println("Oikea vastaus on: " +rightanswer +"\n");}
    //check if all questions are answered} 
else { 
System.out.println("You have answered every question!"); //I know that this is useless.. :D
    }catch(Exception e) {
System.out.println("You made a mistake.");}
 private static boolean areAllQuestionsComplete(int[] list)
    if(list[i] != 1)
        return false;//found one false, then all false
return true;//if it makes it here, then you know its all done

Edit Added whole code 'took some of the questions away' And I'm using CMD

share|improve this question
I am finding it tough to understand your question. Am I the only one? –  Juned Ahsan Aug 17 '13 at 14:18
I'm pretty sure that you know what it looks like no not all of us knows it, and some of us may know how to solve your problem if you include this information. You need to put some more effort in creating your question. Also how are you using/running your application. Is it in OS console? –  Pshemo Aug 17 '13 at 14:20
Check that you're using the correct character encodings. Those characters should display correctly if you're writing them in the correct encoding for the system. (Same for reading). –  kiheru Aug 17 '13 at 14:22
okay, i insert my whole code here <.< ^^ –  minisurma Aug 17 '13 at 14:24
No need for whole code, SSCCE that we can use to reproduce this behaviour will be enough. –  Pshemo Aug 17 '13 at 14:30

2 Answers 2

I'm guessing you are using System.out and System.in which use the systems default encoding.

This is some kind of DOS encoding in the windows command line, depending on your computer settings.

So to allow any kind of Unicode character like äöü and the like to be read and printed as you want to, you have to change your command line encoding (E.g. tell DOS to use a different encoding) and java to use the same encoding.

To correctly answer on how this can be done, one would need more information about your operating system.

on the java side you can use a InputStreamReader and give the character set (encoding) to it's constructor to read and a PrintStream (giving the same encoding as well) to write.

share|improve this answer
That said it's rather hard to get any encoding based problem fixed. I would recommend you to use a window instead of the command line (with Swing for example or SWT). –  kw4nta Aug 17 '13 at 14:30

UTF-8 should enable you to use them.

You're Finnish right? :)

If you try that:

BufferedReader in = new BufferedReader(new InputStreamReader(System.in, "UTF-8"));

How is working for you?

EDIT: Somehow the UTF-8 which should work doesn't seem to do the trick. I tried using -Dfile.encoding=UTF8 as a JVM property but didn't work for me So I tried basically all the charsets which were available and few of them gave the correct characters, here are the charset names: x-ISO-2022-CN-GB, x-ISO-2022-CN-CNS, x-IBM922, windows-1258, windows-1254, windows-1252, ISO-8859-9, ISO-8859-4, ISO-8859-1, ISO-2022-KR and ISO-2022-CN

So if you try for example:

BufferedReader in = new BufferedReader(new InputStreamReader(System.in, "x-ISO-2022-CN-GB"));

It should work

share|improve this answer
I'm a Finn where did you know that? :o –  minisurma Aug 17 '13 at 14:34
Where can i get UTF-8? –  minisurma Aug 17 '13 at 15:52
I have had the same problem than you while dealing with Finnish inputs. I was using Scanner and the solution was something like that: Scanner scanner = new Scanner(new File("fileName.txt"),"UTF-8"); –  Barbe Rouge Aug 17 '13 at 17:46
For me it says this: sanaopisto.java:11: error: unreported exception UnsupportedEncodingException; must be caught or declared to be thrown BufferedReader in = new BufferedReader(new InputStreamReader(System.in, "UTF-8")); ^-- points word new after ( –  minisurma Aug 17 '13 at 18:13
So it's not working.. :/ –  minisurma Aug 18 '13 at 6:59

Your Answer


