Java Unicode变量名称Devanagari

时间:2015-05-30 06:53:58

标签: java unicode

我正在尝试编写一个程序,我试图在梵文的梵文脚本中提供变量名。例如:

class फिल्म
{
    public static void main(String args[])
    {
        String गीत = "Songs";
        System.out.println(गीत);
    }
}

当我尝试执行此Java代码时,它会给我错误

javac program.java

错误

display.java:1: error: illegal character: \0
 ■c l a s s   + ?       2       M       .
             ^
display.java:2: error: illegal character: \0

^
display.java:3: error: illegal character: \0
 {
^
display.java:3: error: illegal character: \0
 {
  ^
display.java:4: error: illegal character: \0

^
display.java:5: error: illegal character: \0
         p u b l i c   s t a t i c   v o i d   m a i n ( S t r i n g   a r g s [ ] )

^
display.java:5: error: illegal character: \0
         p u b l i c   s t a t i c   v o i d   m a i n ( S t r i n g   a r g s [ ] )

        ^
display.java:5: error: illegal character: \0
         p u b l i c   s t a t i c   v o i d   m a i n ( S t r i n g   a r g s [ ] )

                      ^
display.java:5: error: illegal character: \0
         p u b l i c   s t a t i c   v o i d   m a i n ( S t r i n g   a r g s [ ] )

                                    ^
display.java:5: error: illegal character: \0
         p u b l i c   s t a t i c   v o i d   m a i n ( S t r i n g   a r g s [ ] )

                                              ^
display.java:5: error: class, interface, or enum expected
         p u b l i c   s t a t i c   v o i d   m a i n ( S t r i n g   a r g s [ ] )

                                                       ^
display.java:5: error: illegal character: \0
         p u b l i c   s t a t i c   v o i d   m a i n ( S t r i n g   a r g s [ ] )

                                                        ^
display.java:5: error: illegal character: \0
         p u b l i c   s t a t i c   v o i d   m a i n ( S t r i n g   a r g s [ ] )

                                                                      ^
display.java:5: error: illegal character: \0
         p u b l i c   s t a t i c   v o i d   m a i n ( S t r i n g   a r g s [ ] )

                                                                                ^
display.java:5: error: illegal character: \0
         p u b l i c   s t a t i c   v o i d   m a i n ( S t r i n g   a r g s [ ] )

                                                                                  ^
display.java:5: error: illegal character: \0
         p u b l i c   s t a t i c   v o i d   m a i n ( S t r i n g   a r g s [ ] )


^
display.java:6: error: illegal character: \0

^
display.java:7: error: illegal character: \0
         {
^
display.java:7: error: illegal character: \0
         {
        ^
display.java:7: error: illegal character: \0
         {
          ^
display.java:8: error: illegal character: \0

^
display.java:9: error: illegal character: \0
                 S t r i n g   ↨        @       $         =   " S o n g s " ;
^
display.java:9: error: illegal character: \0
                 S t r i n g   ↨        @       $         =   " S o n g s " ;
        ^
display.java:9: error: illegal character: \0
                 S t r i n g   ↨        @       $         =   " S o n g s " ;
                ^
display.java:9: error: illegal character: \0
                 S t r i n g   ↨        @       $         =   " S o n g s " ;
                              ^
display.java:9: error: illegal character: \23
                 S t r i n g   ↨        @       $         =   " S o n g s " ;
                               ^
display.java:9: error: illegal character: \0
                 S t r i n g   ↨        @       $         =   " S o n g s " ;
                                                         ^
display.java:9: error: illegal character: \0
                 S t r i n g   ↨        @       $         =   " S o n g s " ;
                                                           ^
display.java:9: error: illegal character: \0
                 S t r i n g   ↨        @       $         =   " S o n g s " ;
                                                             ^
display.java:9: error: class, interface, or enum expected
                 S t r i n g   ↨        @       $         =   " S o n g s " ;
                                                              ^
display.java:9: error: illegal character: \0
                 S t r i n g   ↨        @       $         =   " S o n g s " ;
                                                                           ^
display.java:9: error: illegal character: \0
                 S t r i n g   ↨        @       $         =   " S o n g s " ;
                                                                             ^
display.java:10: error: illegal character: \0

^
display.java:11: error: illegal character: \0
                 S y s t e m . o u t . p r i n t l n ( ↨        @       $       ) ;

^
display.java:11: error: illegal character: \0
                 S y s t e m . o u t . p r i n t l n ( ↨        @       $       ) ;

        ^
display.java:11: error: illegal character: \0
                 S y s t e m . o u t . p r i n t l n ( ↨        @       $       ) ;

                ^
display.java:11: error: class, interface, or enum expected
                 S y s t e m . o u t . p r i n t l n ( ↨        @       $       ) ;

                             ^
display.java:11: error: illegal character: \0
                 S y s t e m . o u t . p r i n t l n ( ↨        @       $       ) ;

                              ^
display.java:11: error: illegal character: \0
                 S y s t e m . o u t . p r i n t l n ( ↨        @       $       ) ;

                                      ^
display.java:11: error: illegal character: \0
                 S y s t e m . o u t . p r i n t l n ( ↨        @       $       ) ;

                                                      ^
display.java:11: error: illegal character: \23
                 S y s t e m . o u t . p r i n t l n ( ↨        @       $       ) ;

                                                       ^
display.java:11: error: class, interface, or enum expected
                 S y s t e m . o u t . p r i n t l n ( ↨        @       $       ) ;

                                                                                ^
display.java:11: error: illegal character: \0
                 S y s t e m . o u t . p r i n t l n ( ↨        @       $       ) ;

                                                                                 ^
display.java:11: error: illegal character: \0
                 S y s t e m . o u t . p r i n t l n ( ↨        @       $       ) ;

                                                                                   ^

display.java:12: error: illegal character: \0

^
display.java:13: error: illegal character: \0
         }
^
display.java:13: error: illegal character: \0
         }
        ^
display.java:13: error: class, interface, or enum expected
         }
         ^
display.java:13: error: illegal character: \0
         }
          ^
display.java:14: error: illegal character: \0

^
display.java:15: error: illegal character: \0
 }
^
display.java:15: error: illegal character: \0
 }
  ^
52 errors

如何正确执行此代码?

1 个答案:

答案 0 :(得分:7)

以Unicode编码保存文件,然后使用

javac -encoding Unicode program.java

编译它