• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Why wont this run?

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
public class bank
{
public static void main(String argv[])
{
int balanceAMT = Integer.parseInt(argv[0]);
int withdrawnAMT = Integer.parseInt(argv[1]);
int newbalanceAMT = 0;
if(balanceAMT > withdrawnAMT)
{
newbalanceAMT = balanceAMT - withdrawnAMT;
System.out.println("The amount withdrawn is " +withdrawnAMT);
System.out.println("The balance now is " +newbalanceAMT);
}
System.out.println("End of Program");
}
}
I can compile, but attempting to run results in an ArrayIndexOutofBoundsException. What am I missing? Any help would be appreciated. Thanks.
 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by John Collie:
I ran your program as is and it works fine.
You need to run this program from a DOS command line.
I compiled your program and typed in:
java bank 4000 1700
It returned the correct information.
One thing though, class names should begin with a capital letter.
class bank should be class Bank.
Good Luck!

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think must have forgotten to give the arguments while running the program and hence the problem. Anyway such mistakes do happen in the initial learning stages. Good Luck !!!
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic