Handout #1 - Chapter 2 - Chandler High School
Last Name (print): ______________ First Name ______________ 8/4/2006
1. Write the value of the expression after each of the following statements is executed? Make sure you clearly specify the type of the value for each expression.
public class PracticeCh2 {
public static void main (String[] args) {
// declare variables
int k = 0, j = 1;
double x = 2.5, y = -1.5;
int m = 18 , n = 4;
String s = "Hello";
String t = "World";
System.out.println(s.substring(1, 3)); ______________________
System.out.println(s.length() + t.length()); ____________
System.out.println(s + t); ________________________
System.out.println("Hello".compareTo(s)); _____________
System.out.println((int) (10.0 /4.0) * 6 -1 / 2 * 3); _____________________________
System.out.println(1.0 + 15 / 4); ____________________
System.out.println(8 % 3 + (double) (15 / 7) / 2);____________________
System.out.println(5.0 / 4 ); _______________
System.out.println(x + n * y - (x + n) * y); _______________
System.out.println(5 * x - n / 5); ____________________
System.out.println(m / n ); _____________________
System.out.println(m / n + m % n); ______________
System.out.println(Math.pow(x, 2)); _____________________
System.out.println(Math.round(100 * x)); ____________
System.out.println(Math.sqrt (Math.pow(n, 2))); ________________
} // method main
} // class Data