Q:

int to byte, "cannot be resolved to a variable". What is wrong?

what is wrong with this; 
public class cast {

    public static void main(String args[]){
        double x, y; 
        int i;
        char c; 

        x = 10.0; 
        y = 3.0; 

        i = (int) (x / y); 
        System.out.println("Integer outcome of x / y = " + i); 

        i = 100; //Assaigning new value to i. 

        b = (byte) i;  
        System.out.println("The value of i is: " + b); 

    }

}

It gives me the following error message; 
b cannot be resolved to a variable. 
Although I did exactly as they did in the book ( I think, re read the book instruction like five times....) 

A:

b is not a declared variable in your example. Before you can use a variable you have to declare it. If you don't do this Java does not know what b stands for and doesn't know what to do with it.  Try
byte b = (byte) i; 

instead. Alternatively you can also add the line
byte b;

to the beginning of your program. This tells Java that you want b to be a variable that can hold a byte.

