// In-class example // Shows variable declaration and assignment, // and also a conditional. public class ConditionalExamples { public static void main(String[] args){ int a,b,c; // declare three ints int d = 7; // declare and initialize together a = d*d; // some assignment statements b = d-d*d; c = a+b; // == d*d + (d - d*d) == d testValue(a); // variable in a method call testValue(a+b+c+d); // expression in a method call System.out.print("a = " + a + "; b = " + b + "; "); System.out.println("a == b is " + (a == b)); System.out.print("c = " + d + "; d = " + d + "; "); System.out.println("c == d is " + (c == d)); } // This method prints whether x is negative or // non-negative public static void testValue(int x){ if (x < 0) { System.out.println("The value of " + x + " is negative"); } else { System.out.println("The value of " + x + " is non-negative"); } } }