I am having trouple with this simple class:
/** test
* @KPB
*/
public class testofclass
{
static final double RATE = 0.05;
static double purchase;
public static void main(String[] args)
{
double tax;
double total;
purchase=Double.parseDouble(args[0]);
tax = RATE * purchase;
total = purchase + tax;
System.out.println("Total: " + total);
}
}
****
When I compile(which works fine) and run this application, I get this error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
at testofclass.main(testofclass.java:14)
Can anyone provide a quick fix?
Simple class problem
Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard
-
emann
Re: Simple class problem
args[0] = your program name
try
purchase=Double.parseDouble(args[1]);
try
purchase=Double.parseDouble(args[1]);
-
Henrik S. Larsen
Re: Simple class problem
Not in java 
args[0] is the first argument / parameter to the class.
Seems to me, that you are running the class without any arguments
args[0] is the first argument / parameter to the class.
Seems to me, that you are running the class without any arguments
-
Ted Herman
Re: Simple class problem
Yes, I don't think you can define static constants in a class with the main method...