// EqualsExample1
System.out.println("The statement 2 == 4 is");
System.out.println(2 == 4);



// EqualsExample2
int x = 10;
System.out.println(x == 11);



// EqualsMethodExample
Integer I1 = new Integer(2);
Integer I2 = new Integer(2);
System.out.println("Does I1 equal I2?");
System.out.println(I1.equals(I2));






// ComparisonOperatorsExample
int i = 10;
System.out.println(i == 10);
System.out.println(i > 10);
System.out.println(i >= 10);
System.out.println(i < 10);
System.out.println(i <= 10);





// SimpleBooleanExample
boolean b;
b = (12 < 10);




// EqualsVersusEqualsMethodExample
Double d1 = new Double(1.23);
Double d2 = new Double(1.23);
Double d3 = new Double(4.56);
Double d4 = d1;
System.out.println(d1 == d1);
System.out.println(d1 == d2);
System.out.println(d1 == d3);
System.out.println(d1 == d4);
System.out.println(d1.equals(d1));
System.out.println(d1.equals(d2));
System.out.println(d1.equals(d3));
System.out.println(d1.equals(d4));






// StringEqualsExample
String S = new String("Java");
System.out.println(S == "Java");




// TemperatureExample1
int temperature = 95;
if (temperature > 90)
	System.out.println("It's too hot!");
System.out.println("Have a nice day.");






// TemperatureExample2
int temperature = 95;
if (temperature > 90)
{
	System.out.println("It's too hot!");
	System.out.println("I want to go home!");
}
System.out.println("Have a nice day.");






// TemperatureExample3
int temperature = 70;
if (temperature > 90)
{
	System.out.println("It's too hot!");
	System.out.println("I want to go home!");
}
else
{
	System.out.println("It's a warm day.");
	System.out.println("Let's stay here.");
}
System.out.println("Have a nice day.");






// InvalidValueExample1
int i = 20;
if (i < 10)
	System.out.println("Too small.");
	System.out.println("Invalid Value.");
System.out.println("Moving on.");




// InvalidValueExample2
int i = 20;
if (i < 10)
{
	System.out.println("Too small.");
	System.out.println("Invalid Value.");
}
System.out.println("Moving on.");



// GreaterThanExample
int x = 11;	// Change this value as needed.
boolean b = (x > 10);
if (b)
	System.out.println("Too many.");






// GreaterThanPriceExample
double price = 10.0;	// Change as needed.
if (price >= 10.0)
	System.out.println("The price is too high.");
else
	System.out.println("The price is OK.");










// TemperatureExample4
int temperature = 85;	// Change as needed.
if (temperature >= 80)
{
	System.out.println("warm");
	if (temperature < 90)
	{
		System.out.println(" but not too hot");
	}
}
// Done





// PasswordExample
String password = new String("Wrong password");
if (password.equals("peekaboo"))
	System.out.println("success");
else
	System.out.println("Access denied");





// TemperatureExample5
int temperature = 0;	// Change as needed.
if (temperature < 60)
{
	if (temperature < 40)
	{
		System.out.println("Cold");
	}
	else
	{
		System.out.println("Chilly");
	}
}
else
{
	if (temperature <= 80)
	{
		System.out.println("Warm");
	}
	else
	{
		System.out.println("Hot");
	}
}



// LessThanExample
int x = 0;
while (x < 5)
{
	System.out.println(x);
	x = x + 1;
}






// LessThanTooShortExample
String s = "x";
while (s.length() < 4)
{
	System.out.println(s + " is too short.");
	s = s + "x";
}
System.out.println("All Done.");






// WhileVectorExample
// Assume this exists somewhere:
Vector v = new Vector();
// Add elements to v;
v.add(new String("Four"));
v.add(new String("score"));
v.add(new String("and"));
v.add(new String("seven"));
v.add(new String("years"));
v.add(new String("ago"));
// Later . . .
Enumeration e = v.elements();
while (e.hasMoreElements())
{
	Object o = e.nextElement();
	System.out.println(o);
}






// WhileGreaterThanExample
int x = 100;
int y = 0;
while (x > 0)
{
	y++;
	x = x - 10;
}






// ForLoopExample1
for (int x = 0; x < 5; x++)
{
	System.out.println(x);
}





// ForLoopExample2
int x;
for (x = 0; x < 5; x++)
{
	System.out.println(x);
}
System.out.println("x is now " + x);





// ForLoopColorsExample1
String colors[] = {"red", "yellow", "blue", "purple"};
for (int i = 0; i < colors.length; i++)
{
	System.out.println(colors[i]);
}





// ForLoopColorsExample2
String colors[] = {"red", "yellow", "blue", "purple", "green"};
for (int i = 0; i < colors.length; i++)
{
	System.out.println(colors[i]);
}






// ForLoopColorsExample3
String colors[] = {"red", "yellow", "blue", "purple"};
for (int i = 0; i < colors.length; i++)
{
	if (colors[i].equals("blue"))
	{
		System.out.println("name = " + colors[i]);
		System.out.println("index = " + i);
	}
}






// SquaresForLoopExample
int maximum = 10;
for (int i = 0; i <= maximum; i++)
{
	int square = i * i;
	System.out.println(i + " squared is " + square);
}






// SquaresWhileExample
int maximum = 10;
int i = 0;
while (i <= maximum)
{
	int square = i * i;
	System.out.println(i + " squared is " + square);
	i++;
}






// SwitchExample1
int choice = 1;
switch (choice)
{
	case 0:
		System.out.println("Zero");
		break;
	case 1:
		System.out.println("One");
		break;
	case 2:
		System.out.println("Two");
		break;
	default:
		System.out.println("Unknown");
}






// SwitchExample2
char choice = 'c';
switch (choice)
{
	case 'a':
		System.out.println("alpha");
		break;
	case 'b':
		System.out.println("beta");
		break;
	case 'c':
		System.out.println("charlie");
		break;
	default:
		System.out.println("Unknown");
}





// SwitchExample3
int x = 2;
switch (x)
{
	case 0:
	case 2:
	case 4:
		System.out.println("small");
	case 6:
	case 8:
		System.out.println("even");
		break;
	default:
		System.out.println("odd");
}






// SwitchExample4
char grade;
String rating;
// Later
grade = 'B';
switch (grade)
{
	case 'A':
		rating = "Excellent";
		break;
	case 'B':
		rating = "Good";
		break;
	case 'C':
		rating = "Average";
		break;
	case 'D':
		rating = "Poor";
		break;
	case 'F':
		rating = "Failure";
		break;
	default:
		rating = "Confused";
}
System.out.println("Grade is " + grade);
System.out.println("Rating is " + rating);



// SwitchDialPhoneExample
String phoneNumber = "1-800-GOJAVA";
for (int i = 0; i < phoneNumber.length(); i++)
{
	char letter = phoneNumber.charAt(i);
	switch (letter)
	{
		// Same code from Question c
		case 'A': case 'B': case 'C':
			System.out.print('2'); break;
		case 'D': case 'E': case 'F':
			System.out.print('3'); break;
		case 'G': case 'H': case 'I':
			System.out.print('4'); break;
		case 'J': case 'K': case 'L':
			System.out.print('5'); break;
		case 'M': case 'N': case 'O':
			System.out.print('6'); break;
		case 'P': case 'Q': case 'R': case 'S':
			System.out.print('7'); break;
		case 'T': case 'U': case 'V':
			System.out.print('8'); break;
		case 'W': case 'X': case 'Y': case 'Z':
			System.out.print('9'); break;
		default:
			System.out.print(letter);
	}
}
System.out.println();

