Click here to Skip to main content
15,890,825 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Java
publicclassB28Exp2{

public static void main(String[] args) 
{intnum1=(Integer.parseInt(args[0]));
System.out.println("Yourrollno.is"+num1);

for(inti=num1;i<10000;i++){intcheck,rem,sum=0;
check = i;
while(check!=0)
{
rem=check%10;
sum= sum+ (rem*rem*rem);
check=check/10;
}
if(sum==i){
System.out.println(""+i+"isthearmstrongnumberafteryourrollNumber");
break;
}
}
}
}


What I have tried:

Giving an error or array index out of bounds exception : index 0 out of bounds for length 0
Posted
Updated 21-Aug-22 21:27pm
v2

1 solution

You have no arguments passed to your app via the command line: as a result the args array is empty, and there are no valid indexes you can use to access it.

Either pass at least one argument value to it when you run your app, or (better) check if arguments are provided instead of assuming they have been!
 
Share this answer
 
Comments
CPallini 22-Aug-22 3:27am    
5.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900