This is my code to accept 50 names and roll no. and print them alphabetically . It is giving error incompatible type for if(name[j].compareTo(small))
import java .io.*;
class student
{
public void main()throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String name[]=new String[50];
int mark[]=new int[50];
int i;
for( i=0;i<=49;i++)
{
System.out.println("plz ntr d name of d studnt");
name[i]=br.readLine();
System.out.println("plz ntr d marks of d studnt");
mark[i]=Integer.parseInt(br.readLine());
int j,pos=0;
String temp, small;
for(i=0;i<49;i++)
{
small=name[i];
pos=i;
for(j=i+1;j<49;j++)
{
if(name[j].compareTo(small))
pos=j;
}
}
temp=name[i];
name[i]=name[pos];
name[pos]=temp;
}
for(i=0;i<=49;i++)
{
System.out.println((i+1)+" "+name[i]+" "+mark[i]);
}
}
}
compareToreturns anintnot aboolean.What you want is:
EDIT Also, you should check for null: