Why This java code makes an error ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 9

Why This java code makes an error ?

public class Program { public static void main(String[] args) { String[] arrSym = {"!",",","#","@","^",")",":","(","?","-","_","&","

quot;,"₩","¥","£","€","`","<",">","¿","¡",";","《","》","☆","▪","¤","♧","♢","♡","♤","■","□","●","○","•","°","]","[","}","{","<",">","|","~","+","×","÷","=","%","/","*"}; System.out.println(arrSym[5]); } }

17th Jan 2019, 11:55 AM
[SE]شبگرد
[SE]شبگرد - avatar
2 Answers
+ 7
There are some inscrutable characters for compilator. I deleted all them and got this code. public class Program { public static void main(String[] args) { String[] arrSym = {"!",",","#","@","^",")",":","(","?","-","_","&","
quot;,"`","<",">","¿","¡",";","《","》","]","[","}","{","<",">","|","~","+","×","÷","=","%","/","*"}; System.out.println(arrSym[5]); } }
17th Jan 2019, 12:44 PM
Խաչատուր Դալլաքյան
Խաչատուր Դալլաքյան - avatar
+ 5
Most probably the reason is that you are going to try non-ascii chars. Add the following snippet at the top of main then there should be no errors. OutputStreamWriter w = new OutputStreamWriter(System.out,"unicode"); w.write("😆😅"); w.flush();
17th Jan 2019, 12:43 PM
Seniru
Seniru - avatar