469,133 Members | 1,363 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,133 developers. It's quick & easy.

without supplying command line arguments

281 100+
Friends, I wish to consult about this big arithmetic program.
This program basically is calculating big numbers. It work great from command prompt, for instance: java bigal 99999999999999999 + 5.
Is this program works without supplying command line arguments?
If possible then please guide me how to get it to work...really appreciate any help. many thanks.....

Expand|Select|Wrap|Line Numbers
  1. public static void main(String[] args) 
  2.     {
  3.         jonelo.sugar.util.GeneralProgram.requiresMinimumJavaVersion("1.3.1");
  4.         try {
  5.             new Main(args);
  6.         } catch (BigAlException e) 
  7.         {
  8.             System.err.println(e.getMessage());
  9.             System.exit(1);
  10.         }
  11.     }
an excerpt from the Main method ....
Expand|Select|Wrap|Line Numbers
  1. public Main(String[] args) throws BigAlException 
  2.     {
  3.  
  4.         if (args.length < 1) {
  5.             printHelpShort();
  6.             return;
  7.         }
  8.  
  9.         if (args.length < 2) {
  10.             if (args[0].equalsIgnoreCase("help") || args[0].equalsIgnoreCase("-h"))
  11.                 printHelpLong("/help/bigal/help_en.txt"); else
  12.             if (args[0].equalsIgnoreCase("hilfe"))
  13.                 printHelpLong("/help/bigal/help_de.txt"); else
  14.             printHelpShort();
  15.             return;
  16.         }
  17.  
  18.         // operation valid?
  19.         int opcode = receiveOperation(args[1]);
  20.         if (opcode==UNKNOWN) throw new BigAlException("invalid operation");
  21.  
  22.         // general init
  23.         BigInteger b1=null, b2=null, b3=null;
  24.         BigDecimal d1=null, d2=null, d3=null;
  25.         String out="";
  26.         // default init values for fibonacci
  27.         int fibseed0=0;
  28.         int fibseed1=1;
  29.  
  30.         // 2nd number required?
  31.         if (!isSingleOperation(opcode)) {
  32.             if (args.length < 3) {
  33.                 throw new BigAlException("This operation requires a 2nd number!");
  34.             }
  35.             if (isDecimalOperation(opcode))
  36.               d2 = receiveDecNumber(args[2]); else
  37.               b2 = receiveNumber(args[2]);
  38.         }
  39.  
  40.         if (isDecimalOperation(opcode))
  41.           d1 = receiveDecNumber(args[0]); else
  42.           b1 = receiveNumber(args[0]);
  43.  
  44.         // remember the counter
  45.         long begin = System.currentTimeMillis();
  46.         switch (opcode) {
  47.             case ADD:       out=toString(d1.add(d2));
  48.                             break;
  49.             case SUB:       out=toString(d1.subtract(d2));
  50.                             break;
  51.             case MUL:       out=toString(d1.multiply(d2));
  52.                             break;
  53.             case DIV:
  54.  
Mar 9 '07 #1
6 1342
r035198x
13,262 8TB
Friends, I wish to consult about this big arithmetic program.
This program basically is calculating big numbers. It work great from command prompt, for instance: java bigal 99999999999999999 + 5.
Is this program works without supplying command line arguments?
If possible then please guide me how to get it to work...really appreciate any help. many thanks.....

Expand|Select|Wrap|Line Numbers
  1. public static void main(String[] args) 
  2. {
  3. jonelo.sugar.util.GeneralProgram.requiresMinimumJavaVersion("1.3.1");
  4. try {
  5. new Main(args);
  6. } catch (BigAlException e) 
  7. {
  8. System.err.println(e.getMessage());
  9. System.exit(1);
  10. }
  11. }
an excerpt from the Main method ....
Expand|Select|Wrap|Line Numbers
  1. public Main(String[] args) throws BigAlException 
  2. {
  3.  
  4. if (args.length < 1) {
  5. printHelpShort();
  6. return;
  7. }
  8.  
  9. if (args.length < 2) {
  10. if (args[0].equalsIgnoreCase("help") || args[0].equalsIgnoreCase("-h"))
  11. printHelpLong("/help/bigal/help_en.txt"); else
  12. if (args[0].equalsIgnoreCase("hilfe"))
  13. printHelpLong("/help/bigal/help_de.txt"); else
  14. printHelpShort();
  15. return;
  16. }
  17.  
  18. // operation valid?
  19. int opcode = receiveOperation(args[1]);
  20. if (opcode==UNKNOWN) throw new BigAlException("invalid operation");
  21.  
  22. // general init
  23. BigInteger b1=null, b2=null, b3=null;
  24. BigDecimal d1=null, d2=null, d3=null;
  25. String out="";
  26. // default init values for fibonacci
  27. int fibseed0=0;
  28. int fibseed1=1;
  29.  
  30. // 2nd number required?
  31. if (!isSingleOperation(opcode)) {
  32. if (args.length < 3) {
  33. throw new BigAlException("This operation requires a 2nd number!");
  34. }
  35. if (isDecimalOperation(opcode))
  36. d2 = receiveDecNumber(args[2]); else
  37. b2 = receiveNumber(args[2]);
  38. }
  39.  
  40. if (isDecimalOperation(opcode))
  41. d1 = receiveDecNumber(args[0]); else
  42. b1 = receiveNumber(args[0]);
  43.  
  44. // remember the counter
  45. long begin = System.currentTimeMillis();
  46. switch (opcode) {
  47. case ADD: out=toString(d1.add(d2));
  48. break;
  49. case SUB: out=toString(d1.subtract(d2));
  50. break;
  51. case MUL: out=toString(d1.multiply(d2));
  52. break;
  53. case DIV:
  54.  
Create your own array of String args and pass it here:

Expand|Select|Wrap|Line Numbers
  1.  new Main(args);
Replace args with your array of arguments.
Mar 9 '07 #2
shana07
281 100+
Create your own array of String args and pass it here:

Expand|Select|Wrap|Line Numbers
  1.  new Main(args);
Replace args with your array of arguments.
I put this code in main and compile, but no output is given.something wrong in my input parameter then...?
Expand|Select|Wrap|Line Numbers
  1. try 
  2.         {
  3.             String[] arrayArgs = new String[] { "55555" + "6" };
  4.  
  5.             new Main(arrayArgs);
  6.         } catch (BigAlException e) 
Mar 9 '07 #3
horace1
1,510 Expert 1GB
your string initialisation { "55555" + "6" } concatenates to a single string {"555556"}
try initialising the array so
Expand|Select|Wrap|Line Numbers
  1. try 
  2.         {
  3.             String[] arrayArgs = { "55555", "+", "6" };
  4.             new Main(arrayArgs);
  5.         } catch (BigAlException e)
  6.  
Mar 9 '07 #4
horace1
1,510 Expert 1GB
you could also enter your input using a JOptionPane and split the returned string, e.g.
Expand|Select|Wrap|Line Numbers
  1.     try 
  2.         {
  3.             String str = JOptionPane.showInputDialog(null,"enter expression ");
  4.             String[] arrayArgs = str.split(" ");
  5.             Main(arrayArgs);
  6.         } catch (Exception e){}
  7.  
Mar 9 '07 #5
shana07
281 100+
your string initialisation { "55555" + "6" } concatenates to a single string {"555556"}
try initialising the array so
Expand|Select|Wrap|Line Numbers
  1. try 
  2.         {
  3.             String[] arrayArgs = { "55555", "+", "6" };
  4.             new Main(arrayArgs);
  5.         } catch (BigAlException e)
  6.  
Thanks for your help..This one also not giving any output.
I don't know what else should I put to get output.
What kind of arguments that I need to put because the arguments then need to be passed to receiveoperation method. I put again main and receiveOperation here for reference...kindly advise.
Expand|Select|Wrap|Line Numbers
  1. public Main(String[] args) throws BigAlException 
  2.     {
  3.  
  4.         if (args.length < 1) {
  5.             printHelpShort();
  6.             return;
  7.         }
  8.  
  9.         if (args.length < 2) {
  10.             if (args[0].equalsIgnoreCase("help") || args[0].equalsIgnoreCase("-h"))
  11.                 printHelpLong("/help/bigal/help_en.txt"); else
  12.             if (args[0].equalsIgnoreCase("hilfe"))
  13.                 printHelpLong("/help/bigal/help_de.txt"); else
  14.             printHelpShort();
  15.             return;
  16.         }
  17.  
  18.         // operation valid?
  19.         int opcode = receiveOperation(args[1]);
  20.         if (opcode==UNKNOWN) throw new BigAlException("invalid operation");
Expand|Select|Wrap|Line Numbers
  1. private static final int receiveOperation(String operation) {
  2.         int opcode = UNKNOWN;
  3.         operation=operation.toLowerCase();
  4.         if (operation.equals("add") || operation.equals("+"))
  5.             opcode = ADD; else
  6.         if (operation.equals("sub") || operation.equals("-"))
  7.             opcode = SUB; else
  8.         if (operation.equals("mul") || operation.equals("*") || operation.equals("x") )
  9.             opcode = MUL; else
  10.         if (operation.equals("div") || operation.equals("/") || operation.equals(":") )
  11.             opcode = DIV; else
  12.         if (operation.equals("divide") || operation.equals("//") || operation.equals("::") )
  13.             opcode = DIVIDE; else
  14.         if (operation.equals("mod") || operation.equals("%"))
  15.             opcode = MOD; else
  16.         if (operation.equals("fib") || operation.equals("fibonacci"))
  17.             opcode = FIB; else
  18.         if (operation.equals("luc") || operation.equals("lucas"))
  19.             opcode = LUC; else
  20.         if (operation.equals("nk") || operation.equals("choose"))
Mar 10 '07 #6
shana07
281 100+
your string initialisation { "55555" + "6" } concatenates to a single string {"555556"}
try initialising the array so
Expand|Select|Wrap|Line Numbers
  1. try 
  2.         {
  3.             String[] arrayArgs = { "55555", "+", "6" };
  4.             new Main(arrayArgs);
  5.         } catch (BigAlException e)
  6.  
Sorry, I've made wrong.
This one works! Thanks to you...
I understand about String now.
Mar 14 '07 #7

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

6 posts views Thread by Hari | last post: by
33 posts views Thread by ankursinha | last post: by
1 post views Thread by Rune Jacobsen | last post: by
4 posts views Thread by Roland | last post: by
2 posts views Thread by Milan | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.