Why when I run this it gives zero instead of the character a:
public class Main {
public static void main(String[] args) {
int num = 79;
char a = 'a';
System.out.println((char)num);
}
}
Why when I run this it gives zero instead of the character a:
public class Main {
public static void main(String[] args) {
int num = 79;
char a = 'a';
System.out.println((char)num);
}
}
You have an typo:
To get the lowercase letter 'a', use 97 instead of 79.
When you cast a number to a character it will look the ASCII
value of that particular number which in your case is O
(CAPITAL O).
If you want to print a
use 97
See the ASCII chart for further reference: https://ascii.cl/