Source code:
import java.util.Arrays;
class Uglynumbers {
/**
* @param arg
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
long[] ugly= new long[1510];
long inter1,inter2,inter3;
int count=0;
boolean found1=false,found2=false,found3=false;
ugly[0]=1;
ugly[1]=2;
ugly[2]=3;
ugly[3]=5;
count=4;
for (int i=1; i<1500;i++)
{
found1=found2=found3=false;
inter1= ugly[i]*2;
inter2= ugly[i]*3;
inter3= ugly[i]*5;
for(int z=count-1;z>=0;z--)
{
if((inter1>ugly[z]) && (inter2>ugly[z]) && (inter3>ugly[z]))
break;
else
{
if(ugly[z]==inter1)
found1=true;
if(ugly[z]==inter2)
found2=true;
if(ugly[z]==inter3)
found3=true;
}
if( found1 && found2 && found3)
break;
}
if(!found1)
{
ugly[count]=inter1;
count+=1;
}
if(!found2)
{
ugly[count]=inter2;
count+=1;
}
if(!found3)
{
ugly[count]=inter3;
count+=1;
}
Arrays.sort(ugly,0,count);
if(count>=1500)
break;
}
System.out.println("The 1500'th ugly number is "+ ugly[1499]);
System.exit(0);
}
};
When I run this code in eclipse its working fine. But when i give it UVA online judge, am getting following run time error: “”136 – Ugly Numbers has failed with verdict Runtime error.
This means that the execution of your program didn’t finish properly. Remember to always terminate your code with the exit code 0″.”
What am missing in the code?
It seems that it requires the class to be called Main.
http://code.google.com/p/collatz-deandalm/issues/detail?id=13
EDIT:
Entire Java specification:
http://uva.onlinejudge.org/index.php?option=com_content&task=view&id=15&Itemid=30
Get rid of this:
System.exit(0);And change
UglynumberstoMain.