How come I can't get into the else? where did I go wrong? I would like to do this test based on this structure that I have outlined.
I don't want to use switches and other things.
Only with this structure.
public static void main(String[] args) { String a = "10"; String b = "6"; boolean t = false; boolean v = false; for (int i = 0; i < a.length(); i++) { for (int j = 0; j < b.length(); j++) { if (a.equals(b)) { t = true; System.out.println("sono uguali"); } } if (t == false) { if(a != b) { System.out.println("non sono uguali: " + a + "!=" + b); } else { v= true; if(a.equals("10")) { System.out.println("Non inserire il numero 10"); } } } } }
suppose that a and b are objects, does this approach work the same?
does not enter mepublic static void main(String[] args) { String a = new String(); String b = new String(); boolean t = false; boolean v = false; a = "10"; b = "7"; for (int i = 0; i < a.length(); i++) { for (int j = 0; j < b.length(); j++) { if (a.equals(b)) { t = true; System.out.println("sono uguali"); } } if (t == false) { if (a != b) { System.out.println("non sono uguali: " + a + "!=" + b); } else { if (a.equals("10")) { v = true; System.out.println("Should not be 10"); } } } } } }
if (a.equals("10")) {
v = true;
System.out.println("Should not be 10");
}
suppose there is get and set does it work the same?