Advertisement
476179

ArithmaticOperators

Sep 25th, 2019
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.01 KB | None | 0 0
  1. package lessons;
  2.  
  3. public class ArithmeticOperators
  4. {
  5. /*
  6. *
  7. * shortust to systm.out.print is 'syso'+Ctrl+space
  8. *
  9. */
  10. public static void main(String[] args)
  11. {
  12. // unary opertor needs one operand to affect change,
  13. //binary requries 2
  14. // turniariy requires 3
  15. System.out.println("Ex1, Unary Operand");
  16. int num = 5;
  17. num = -num;
  18. //this is unary operator bec it uses only one #
  19. System.out.println(" the unary operator requires"
  20. + " only one operand\n value: "+num);
  21.  
  22. System.out.println("\nEx2, Addition Operator");
  23. int amount,total,priceA = 10, tax = 3, numA = 0;
  24. amount = 4+8;
  25. total = priceA + tax;
  26. numA = numA + 1;
  27. System.out.println(" the result of amount is: "+ amount
  28. +"\n the result of toal is: "
  29. + total+"\n the result of numA is: "+numA);
  30.  
  31. System.out.println("\nEx3, Subtraction Operator");
  32. int temp, sale, priceB = 5, numB = 0, discount = 3;
  33. temp = 112 - 14;
  34. sale = priceB - discount;
  35. numB = numB - 1;
  36. System.out.println(" The temperature is: "+temp
  37. +"\n the result of sale is: "+sale
  38. +"\n the result of numB is: "+numB);
  39.  
  40. System.out.println("\nEx4, Multipication Operator");
  41. int pop = 2;
  42. double markUp, percent = 0.02, sales = 3, commission;
  43. markUp = 12 * .25;
  44. commission = sales * percent;
  45. pop = pop * 2;
  46. System.out.println(" the markup is: "+markUp+
  47. "\n the commission is: "+commission+
  48. "\n the population is: "+pop);
  49.  
  50. System.out.println("\nEx5, Division Operators");
  51. double points, teams, players=11, maxE=3,half,num3=23;
  52. points = 100/20;
  53. teams = players/maxE;
  54. half = num3/2;
  55. System.out.println(" points: "+points+
  56. "\n teams: "+teams+"\n half: "+half);
  57.  
  58. System.out.println("\nEx6, Modulus Operator");
  59. //modulus gives remainder of division
  60. //ex. 11%2 is 1 bec 2 goes into 11 5 times with 1 left over
  61. int leftOver;
  62. leftOver = 17 % 3;
  63. System.out.println(" result of leftover is: "+leftOver);
  64.  
  65.  
  66.  
  67. }
  68.  
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement