/1. How much memory is being reserved here? 32 bit. //Throw an error message on line 52 by making x a constant. int x = 999; ++x; //++x is a shortcut for x = x + 1 or x+=1 System.out.println(x); */ /** //2. if I don't assign it anything what goes in there? we will get an error. // NOW local variable. (Look stack flow link) //Discuss this and come up with a theory. //Why is this a bad idea. int x; System.out.println(x); */ //3. How could this be useful? //Why is there a limit? System.out.println(Integer.MAX_VALUE); System.out.println(Integer.MIN_VALUE); System.out.println(Double.MAX_VALUE); System.out.println(Double.MIN_VALUE); /*
Please explain the questions below:
//1. How much memory is being reserved here? 32 bit.
//Throw an error message on line 52 by making x a constant.
int x = 999;
++x; //++x is a shortcut for x = x + 1 or x+=1
System.out.println(x);
*/
/**
//2. if I don't assign it anything what goes in there? we will get an error.
// NOW local variable. (Look stack flow link)
//Discuss this and come up with a theory.
//Why is this a bad idea.
int x;
System.out.println(x);
*/
//3. How could this be useful?
//Why is there a limit?
System.out.println(Integer.MAX_VALUE);
System.out.println(Integer.MIN_VALUE);
System.out.println(Double.MAX_VALUE);
System.out.println(Double.MIN_VALUE);
/*
//4. For each line:
//uncomment the print statement and the run each line one at a time by
//commenting one back in and then back out.
// predict what's going to happen
// observe the actual results
// explain what's going on if you can
int x = 4.6; //What is this type of conversion called?
int x = (int)4.6; //What is this type of conversion called?
int x = 9/4;
//System.out.println(x);
//5. Explain what's going on
/*
double y = 5.8;
//int x = y;
int x = (int) y;
System.out.println(x);
System.out.println(y);
*/
//6. Explain what's going on. When would you use this data type?
/*
byte x = 126;
System.out.println(x);
x = 127; x++;
System.out.println(x);
*/
//7. Explain what's going. on. When would you use this data type?
/*
//short x = 32768;
//System.out.println(x);
short x = 32767; x++;
System.out.println(x);
*/
//8. Experiment with the below code. When would you use this data type?
// In Java "or" is represented by || and "and" is represented as &&
//boolean x = 0;
//boolean x = true;
//x = !x;
//x = x || false;
//System.out.println(x);
//9. Explain what's going on here.
//char x = 'A';
//char x = 65;
//char x = 'A'; x++;
//char x = 12;
//System.out.println("x = " + x);
Step by step
Solved in 4 steps