How to use Ä, Ö & Å in java input?
So. I'm wondering how could i make it so that
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)
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
answer.equals(rightanswer)
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) {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
try{
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");
getquestion(quanity);
}
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) {
try{
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
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.println(question);
System.out.print("Vastaus?: ");
answer = in.readLine();
if (answer.equals(rightanswer)){
right++;
System.out.println("Oikein!\n");
done[ran] = 1;}
else{wrong++;
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)
{
for(int i = 0; i<list.length; i++)
{
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'
No comments:
Post a Comment