如何以原始形式打印非拉丁字符?

时间:2015-11-03 01:46:50

标签: java arrays unicode char

我正在尝试创建一个打印随机阿拉伯字符的程序。然后,用户输入程序验证的罗马化语句。该程序重复此过程。

我的程序打印出,而不是打印出原始字符。你能确定问题吗?

import java.lang.Math;
import java.util.Scanner;

class Arabic_Randomizer{
  public static void main(String[] args){

//the variables for 
//    char [] EngLetterEqv = {'a','b','g','d','h','w','z','h','t','y','k','l','m','n','s','','','','','','','','','',''};
    char [] achar = {'غ' , 'ظ' , 'ض' , 'ذ' , 'خ' , 'ث' , 'ت' , 'ش' , 'ر' , 'ق' , 'ص' , 'ف' , 'ع' , 'س' , 'ن' , 'م' , 'ل' , 'ك' , 'ي' , 'ط' , 'ح' , 'ز' , 'و' , 'ه' , 'د' , 'ج' , 'ب' , 'ا' };
    String [] ason = { "alif" , "baa" , "jim" , "dal" , "ha(2)", "wow" , "zai" , "ha(1)" , "ta" , "ya" , "kaf" , "lam" , "miim" , "noon" , "sin" , "'ayn" , "faa" , "sad" , "qaf" , "raa" , "scin" , "taa" , "tha" , "kai" , "dhal" , "Dad" , "za", "ghayn"};
    int randr = 0;
    int oi = 1;
    String ans = null;
    Scanner scan = new Scanner(System.in);

// The "Game Loop"
    while (oi != 0){
      //Randomizer
      randr = (int) Math.random()*27;
      if (randr == 28){randr--;}
      //Selector & output
      System.out.println("What letter is this "+ achar[randr]);
      ans = scan.nextLine();
      //Check
      if (ans.equals(ason[randr])){System.out.println("Correnct");}
      else{System.out.println("Wrong");}
      //
      System.out.println("Please press 0 then enter if you would like to stop, press any other integer if you would like to continue; ");
      oi = scan.nextInt();
    }
  }
}

我在DrJava编码;这可能是问题吗?我是Java和编程的新手,所以请使用简单的响应。

2 个答案:

答案 0 :(得分:0)

只需将scan.nextLine();放在oi=scan.nextInt();之下即可。

答案 1 :(得分:0)

正如用户msandiford所说,您需要支持扩展字符集。正如他所说的那样,Eclipse为此做了诀窍。与俄语字符有同样的问题。

这将帮助您朝着正确的方向前进: http://docs.oracle.com/javase/7/docs/api/java/nio/charset/Charset.html