source code to show the int literals
// sample program to show the int literals
package literals;
public class IntLiteralExample {
public static void main(String[] args) {
int i='a';
int j=10;
byte b1='b';
char ch='b';
//int i=123.34 ------> not valid
//byte b=ch; ------>THIS STATEMENT GIVES ERROR (PLP found : char reqired: byte
System.out.println(i);
System.out.println(j);
System.out.println(ch);
//System.out.println(b);
}
}
output:
97
10
b
4 comments:
how int i='a' answer is 97
because of Unicode. Every character have the unicode..here that unicode is convert to int and showing us
In byte b=ch; why ch can't be assigned to byte. why It can't covert 'b' into 98.
char data type size is 2 bytes , we are assigning into 1 byte of byte data type so it won't allow..It won't consider what value is it..it will check size of the data type.
Post a Comment