Basically I am developing a program that involves matrices, I am AWARE AND DO NOT CORRECT that the matrix provided can be a simple array but that disproves what I am going for here.
Anyways the code provided below supplies 3 methods that each have a code that I have tried to compare the two values and in each case, it fails. If anyone can point out the error, that would be great.
public class TestingLength {
public static String[][] locatedNum = {{"1","2","3"}};
public static int num = 3;
public static void test() {
System.out.println("Finding Number " + locatedNum[0][2] + " With Number " + num);
if(locatedNum[0][2] == ""+num) {
System.out.println("Example Worked!");
return;
}else
System.out.println("Example Failed!");
}
public static void test2() {
System.out.println("Finding Number " + locatedNum[0][2] + " With Number " + num);
if(locatedNum[0][2].equals(num)) {
System.out.println("Example Worked!");
return;
}else
System.out.println("Example Failed!");
}
public static void test3() {
String s = Integer.toString(num);
System.out.println("Finding Number " + locatedNum[0][2] + " With Number " + num);
if(locatedNum[0][2] == s) {
System.out.println("Example Worked!");
return;
}else
System.out.println("Example Failed!");
}
public static void main(String[] args) {
test();
test2();
test3();
}
}