Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- == Halving Method =======================================
- half(2); // calling method
- public void half(int input) {
- input = input / 2; // output would be 1
- }
- =========================================================
- == Doubling Method ======================================
- doub(2); // calling method
- public void doub(int input) {
- input = input * 2; // output would be 4
- }
- =========================================================
- == Parity Method ========================================
- parity(2); // calling method
- public boolean parity(int input) {
- return (input % 2 == 0) ? 1 : 0; // returns 1 if even, returns 0 if odd
- }
- =========================================================
- == Sorting Method =======================================
- sort(asc, test_list); // calling method
- public void sort(String SORTBY, ArrayList ARRAYLIST) {
- switch (SORTBY.toLowerCase()) {
- case "asc": // sort by ascending order
- Collections.sort(ARRAYLIST);
- break;
- case "desc": // sort by descending order
- Collections.sort(ARRAYLIST, Collections.reverseOrder());
- break;
- default:
- break;
- }
- }
- =========================================================
- == System Information Methods ===========================
- getOS(); // calling getOS Method
- getOSVersion(); // calling getOSVersion Method
- getCores(); // calling getCores Method
- getFreeMem(); // calling getFreeMem Method
- getMaxMem(); // calling getMaxMem Method
- getTotalMem(); // calling getTotalMem Method
- public String getOS() {
- return System.getProperty("os.name"); // returns the OS name
- }
- public double getOSVersion() {
- return System.getProperty("os.version"); // returns the OS version
- }
- public String getArch() {
- return System.getProperty("os.arch"); // returns the OS architecture
- }
- public int getCores() {
- return Runtime.getRuntime().availableProcessors(); // returns available core count
- }
- public long getFreeMem() {
- return Runtime.getRuntime().freeMemory(); // returns free memory
- }
- public long getMaxMem() {
- return Runtime.getRuntime().maxMemory(); // returns max memory
- }
- public long getTotalMem() {
- return Runtime.getRuntime().totalMemory(); // returns total system memory
- }
- =========================================================
Advertisement
Add Comment
Please, Sign In to add comment