Win a copy of Mastering Corda: Blockchain for Java Developers this week in the Cloud/Virtualization forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

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 !!!
 
reply
    Bookmark Topic Watch Topic
  • New Topic