Java default Integer value is int
Posted
by
Chris Okyen
on Programmers
See other posts from Programmers
or by Chris Okyen
Published on 2012-10-10T23:36:36Z
Indexed on
2012/10/11
3:51 UTC
Read the original article
Hit count: 530
My code looks like this
import java.util.Scanner;
public class StudentGrades {
public static void main(String[] argv)
{
Scanner keyboard = new Scanner(System.in);
byte q1 = keyboard.nextByte() * 10;
}
}
It gives me an error "Type mismatch: cannot convert from int to byte." Why the heck would Java store a literal operand that is small enough to fit in a byte,. into a int type? Do literals get stored in variables/registers before the ALU performs arithmatic operations.
© Programmers or respective owner