SOURCE CODE FILES FOR Primitive EXAMPLES Variables, Operators =============================================================================== * Project Variables * Class Main * * Illustrate the use of variables in Java. */ public class Main { public static void main(String[] args) { // Integer variables. int x, y = 34, z; x = -21; z = 372639; System.out.println(x + " " + y + " " + z); // Floating point variables. double a, b = 387.68574; a = -9.24; System.out.println(a + " " + b); // Character variables. char s = 'P', t = '#', u; u = '4'; System.out.println(s + " " + t + " " + u); // Boolean variables. boolean f, g; f = true; g = false; System.out.println(f + " " + g); } } // Output: -21 34 372639 -9.24 387.68574 P # 4 true false =============================================================================== /** * Project Operators * Class Main * * Illustrate some of the Java operators. */ public class Main { public static void main(String[] args) { // Arithmetic operators // Remember the precedence of operations. int x = 3, y = 8, z = 12, w; w = x + y * z - 7; System.out.println(x + " " + y + " " + z + " " + w); // String concatenation String m = "dog", n = "cat", k; k = n + m; System.out.println(m + " " + n + " " + k); // Comparison operators boolean f, g; f = (x >= y - 4); g = (2 * z == y); System.out.println(f + " " + g); // Logical operators f = true && false; g = (1 == 2) || (5 == 5); System.out.println(f + " " + g); // Assignment operators x += y; y *= (2 + z); w /= 3; System.out.println(x + " " + y + " " + z + " " + w); } } // Output: 3 8 12 92 dog cat catdog false false false true 11 112 12 30 ===============================================================================