pastebin - collaborative debugging

pastebin is a collaborative debugging tool allowing you to share and modify code snippets while chatting on IRC, IM or a message board.

This site is developed to XHTML and CSS2 W3C standards. If you see this paragraph, your browser does not support those standards and you need to upgrade. Visit WaSP for a variety of options.

ixpict private pastebin - collaborative debugging tool What's a private pastebin?


Posted by ixpict on Sat 2 May 14:39
report abuse | download | new post

  1. package Calc;
  2.  
  3. import java.math.*;
  4.  
  5. public class Calculator {
  6.  
  7. /**
  8. * Простейший консольный калькулятор
  9. *
  10. * @param args
  11. * TODO разобарться как работает
  12. */
  13. public static void main(String[] args) {
  14. if (args.length < 3) {
  15.  
  16. System.err.println("Usage: Java Calc operand operator operand");
  17.  
  18. return;
  19. }
  20. BigDecimal a = new BigDecimal(args[0]);
  21.  
  22. BigDecimal b = new BigDecimal(args[2]);
  23.  
  24. switch (args[1].charAt(0)) {
  25.  
  26. case '+':
  27. System.out.println(a.add(b));
  28. break;
  29.  
  30. case '-':
  31. System.out.println(a.subtract(b));
  32. break;
  33.  
  34. case '*':
  35. System.out.println(a.multiply(b));
  36. break;
  37.  
  38. case '/':
  39. System.out.println(a.divide(b,BigDecimal.ROUND_HALF_EVEN));
  40. break;
  41.  
  42. default:
  43. System.out.println("Invalid operator");
  44.  
  45. }
  46. }
  47. }

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with @@


Remember me so that I can delete my post