MrSparkzz

Java Methods

Aug 30th, 2013
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.26 KB | None | 0 0
  1. == Halving Method =======================================
  2. half(2); // calling method
  3.  
  4. public void half(int input) {
  5.     input = input / 2; // output would be 1
  6. }
  7. =========================================================
  8.  
  9. == Doubling Method ======================================
  10. doub(2); // calling method
  11.  
  12. public void doub(int input) {
  13.     input = input * 2; // output would be 4
  14. }
  15. =========================================================
  16.  
  17. == Parity Method ========================================
  18. parity(2); // calling method
  19.  
  20. public boolean parity(int input) {
  21.     return (input % 2 == 0) ? 1 : 0; // returns 1 if even, returns 0 if odd
  22. }
  23. =========================================================
  24.  
  25. == Sorting Method =======================================
  26. sort(asc, test_list); // calling method
  27.  
  28. public void sort(String SORTBY, ArrayList ARRAYLIST) {
  29.     switch (SORTBY.toLowerCase()) {
  30.         case "asc": // sort by ascending order
  31.             Collections.sort(ARRAYLIST);
  32.             break;
  33.         case "desc": // sort by descending order
  34.             Collections.sort(ARRAYLIST, Collections.reverseOrder());
  35.             break;
  36.         default:
  37.             break;
  38.     }
  39. }
  40. =========================================================
  41.  
  42. == System Information Methods ===========================
  43. getOS(); // calling getOS Method
  44. getOSVersion(); // calling getOSVersion Method
  45. getCores(); // calling getCores Method
  46. getFreeMem(); // calling getFreeMem Method
  47. getMaxMem(); // calling getMaxMem Method
  48. getTotalMem(); // calling getTotalMem Method
  49.  
  50. public String getOS() {
  51.     return System.getProperty("os.name"); // returns the OS name
  52. }
  53.  
  54. public double getOSVersion() {
  55.     return System.getProperty("os.version"); // returns the OS version
  56. }
  57.  
  58. public String getArch() {
  59.     return System.getProperty("os.arch"); // returns the OS architecture
  60. }
  61.  
  62. public int getCores() {
  63.     return Runtime.getRuntime().availableProcessors(); // returns available core count
  64. }
  65.  
  66. public long getFreeMem() {
  67.     return Runtime.getRuntime().freeMemory(); // returns free memory
  68. }
  69.  
  70. public long getMaxMem() {
  71.     return Runtime.getRuntime().maxMemory(); // returns max memory
  72. }
  73.  
  74. public long getTotalMem() {
  75.     return Runtime.getRuntime().totalMemory(); // returns total system memory
  76. }
  77. =========================================================
Advertisement
Add Comment
Please, Sign In to add comment