1.
class IncDecOp { //start of class block
//Example to illustrate increment and decrement operators
public static void main(String [] args) { // start of method block
int a = 20, b = 0;
//Prints out initial values of a & b
System.out.println("a ="+ a + "b =" + b);
// Value of b is assigned the original value of a before the increment operation
b = a++;
System.out.println("a ="+ a + " b =" + b);
a = 20;
b = ++a;
System.out.println("a ="+ a + " b =" + b);
a = 20;
b = a--;
System.out.println("a ="+ a + " b =" + b);
a = 20;
b = --a;
System.out.println("a ="+ a + " b =" + b);
} //end of method block
} //end of class block
Values of a & b:
a =20 b =0
a =21 b =20
a =21 b =21
a =19 b =20
a =19 b =19
2.
class Cast {
public static void main(String [] args) {
double a = 1.5;
int b = 2;
int c = (int) a*b; //Explicitly stating that you need the value to be
rounded to an int
System.out.println("c = "+ c);
}
}
Solutions for the Extra Credit Problems Spring
&file=HullFund8eCh07ProblemSolutions
&file=HullFund8eCh17ProblemSolutions
Tags: class incdecop, 2. class, incdecop, start, solution, class