hi,
I have this method
public void record()
{
Scanner input = new Scanner( System.in );
int sid;
for ( int counter = 0; counter < length; counter++ )
{
System.out.println("Student " + (counter+1) + " Record");
System.out.println("****************");
System.out.print("Enter SID: ");
a[ counter ] = input.nextInt();
sid=a[counter];
if (isUnique(sid))
{
System.out.print("Enter SName: ");
b[ counter ] = input.next();
System.out.print("Enter SGrade: ");
c[ counter ] = input.nextInt();
System.out.println("****************");
}
else
{
System.out.println("Student id is not unique");
}
}
}
which in part of it call another method which check the if a student id exist in an array or not.
public boolean isUnique(int id)
{
for(int i=0; i<length;i++)
{
if(id == a[i])
{
return false;
}
}
return true;
}
The code works fine but I keep always getting
that the Student id is not unique.
Could anyone here help finding what's wrong with this code.
Thanks in advance.