Programming Resources
For Fun and Learning
Charles Cusack
Computer Science
Hope College
main

Python
C++

JAVA


PHP
SQL
Alice

EqualityAndSwap


EqualityAndSwap.java

EqualityAndSwap.java

public class EqualityAndSwap {

//-------------------------------------------------------
// Look at the method equalityVersusEquals.
// What does it print? 
// (Each line prints "true" or "false")
public static void equalityVersusEquals() {
		String s1 = new String("One");
		String s2 = new String("One");
		String s3 = new String("Three");
		String s4 = s1;
		String s5 = "One";
		String s6 = "One";

		System.out.println(s1==s2); 
		System.out.println(s1==s3);
		System.out.println(s1==s4);
		System.out.println(s1==s5); 
		System.out.println(s2==s4);
		System.out.println(s5==s6);
		System.out.println(s1.equals(s2)); 
		System.out.println(s1.equals(s3));
		System.out.println(s1.equals(s4));
		System.out.println(s1.equals(s5));
		System.out.println(s1.equals(s6)); 
		System.out.println(s2.equals(s4));
		System.out.println(s5.equals(s6));
	}

//-------------------------------------------------------
// Do stuff shows you something very interesting in Java.
// What do you think it prints?  
// It is important to note that this is an example of a
// possible limitation that Java has.  We will discuss
// this in class.
public static void DoStuff() {
		String s1 = new String("One");
		String s2 = new String("Two");
		System.out.println(s1 + "<->" + s2);
		Swap(s1,s2); 
		System.out.println(s1 + "<->" + s2);
		
		int i1=1, i2=2;
		System.out.println(i1 + "<->" + i2);
		Swap(i1,i2); 
		System.out.println(i1 + "<->" + i2);
	}	
//-------------------------------------------------------
	public static void Swap(int A, int B) {
		int temp = A;
		A = B;
		B = temp;
	}
	public static void Swap(String A, String B) {
		String temp = A;
		A = B;
		B = temp;
	}
//-------------------------------------------------------

}