Question

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 would Java store a literal operand that is small enough to fit in a byte, into an int type? Do literals get stored in variables/registers before the ALU performs arithmetic operations?

No correct solution

Licensed under: CC-BY-SA with attribution
scroll top