Why in line 22 it has to be System.out.print((char)a) instead of System.out.print(a)?
If i did System.out.print(a) it apeared
Why in line 22 it has to be System.out.print((char)a) instead of System.out.print(a)?
Archived
Comments (7)
- Popular
- New
- Old
You must be signed in to leave a comment
Guadalupe Gagnon
7 February 2019, 21:25
cant read
0
Wojtek
7 February 2019, 21:29
Why in line 22 it has to be System.out.print((char)a) instead of System.out.print(a)?
0
Guadalupe Gagnon
7 February 2019, 21:31
it is because the filereader.read method only returns an int, which you capture on line 21, that corresponds to the ASCII table value of the character being read. When you output just 'a' the computer does not know 'a' is anything but an int. You need to cast to a char with the code you mentioned so that the computer outputs the character and not the ASCII number for the character.
http://www.asciitable.com/
+1
Guadalupe Gagnon
7 February 2019, 21:35
Try this code out:
+1
Guadalupe Gagnon
7 February 2019, 21:36
If you look at the ASCII table and run that code you can compare values from that to what is output.
+1
Wojtek
7 February 2019, 21:47
thanks Guadalupe! :)
+1
Guadalupe Gagnon
7 February 2019, 21:48
anytime
0