Java Problem. Please help!?

I am creating your lab exactly where someone enters the brands of students and if a identify is repetitive, a principles will pop up saying that other people has exactly the same name.Nonetheless, whenever WE run the item, that meaning never seems.This is the main a part of the laboratory.I obviously have an additional file in which returns the primary and previous names (getFirst, getLast) and several other parts from the lab we have not necessarily shown

Stringed first = “”;
Stringed last = “”;
Stringed password = “”;

System.out.println(“How a lot of students is there “);
int numOfStudents = enter.nextInt();

with regard to (int i=0; i<numOfStudents; i++)
System.out.println(“Enter the primary name with student ” + (i+1));
very first = input.next();
System.out.println(“Enter the final name with student ” + (i+1));
continue = input.next();
System.out.println(“Enter that password associated with student ” + (i+1));
password = enter.next();
even though (! Scholar.rightLength(password)! Scholar.okDigit(password)! Scholar.okUpperCase(password))
System.out.println(“Invalid password.Please try once again:”);
password = enter.next();

arrayi = fresh Student(first, last);
arrayi.setPassword(password);
with regard to (int j=-1; j<i; j++)
in the event (j >= 0)
in the event ((arrayi.getFirst() == arrayj.getFirst()) && (arrayi.getLast() == arrayj.getLast()))
System.out.println(“Someone else has a similar name when you.”);
// conclude if j > 0
//end j loop

//end we loop

The message never is found because you will be comparing objects with the == rider.Remember that will in Coffee, an subject variable includes a reference for you to an subject, not this object itself.When you utilize ==, you’re comparing the references, not the content in the objects.It will eventually only be true regarding both issues are references on the same subject.

This links with any object type, which includes String, which is presumably what getFirst() and getLast() give back.If you need to compare the particular values with Strings, utilize the equals() system instead.

By way of example:

if((arrayi.getFirst().equals(arrayj…etc ..

Spend money on your second question:espresso.util.Arrays is not a system.It’s the class.It carries a sort() method you can use to be able to sort an array.Check available the documentation hard at that link beneath.

Leave a Reply