Code Monkey home page Code Monkey logo

codereuseutility's Introduction

Java Code Utility - CodeReuse

This repository provides a Java utility class 'CodeReuse' that encapsulates commonly used methods for array manipulation and matrix operations.

Features

Methods Included:

1. sortAscending

Sorts an array of integers in ascending order.

Usage Example:

import com.example.CodeReuse;
import java.util.Arrays;

public class SortArrayExample {
    public static void main(String[] args) {
        int[] array = {4, 2, 7, 1, 9};

        // Sort the array
        CodeReuse.sortAscending(array);
        System.out.println("Sorted Array: " + Arrays.toString(array));
    }
}

2. calculateStats

Computes maximum, minimum, and average values of an integer array.

Usage Example:

import com.example.CodeReuse;

public class CalculateStatsExample {
    public static void main(String[] args) {
        int[] array = {4, 2, 7, 1, 9};

        // Calculate statistics
        double[] stats = CodeReuse.calculateStats(array);
        System.out.println("Max: " + stats[0]);
        System.out.println("Min: " + stats[1]);
        System.out.println("Average: " + stats[2]);
    }
}

3. matrixAddition

Adds two matrices and returns the resultant matrix.

Usage Example:

import com.example.CodeReuse;
import java.util.Arrays;

public class MatrixAdditionExample {
    public static void main(String[] args) {
        int[][] matrixA = {
            {1, 2},
            {3, 4}
        };
        int[][] matrixB = {
            {5, 6},
            {7, 8}
        };

        // Perform matrix addition
        int[][] resultMatrix = CodeReuse.matrixAddition(matrixA, matrixB, 2, 2);
        // Display the resultant matrix
        for (int[] row : resultMatrix) {
            System.out.println(Arrays.toString(row));
        }
    }
}

Usage

Using the CodeReuse Class

  1. Clone or Download the Repository

    • Clone the repository:
      git clone https://github.com/fahad-678/CodeReuseUtility.git
    • Or download the ZIP file and extract it.
  2. Add CodeReuse.jar to Your Project

    • Copy CodeReuse.jar from the repository to your Java project's directory.
  3. Add JAR to Classpath or Dependency Management

    • Classpath Method:

      • Add the JAR to your project's classpath.
      • Import the CodeReuse class:
        import com.example.CodeReuse; // Update package name accordingly
    • Maven:

      • Add as a dependency in your pom.xml:
        <dependency>
            <groupId>com.example</groupId>
            <artifactId>CodeReuse</artifactId>
            <version>1.0</version>
            <scope>system</scope>
            <systemPath>/path/to/CodeReuse.jar</systemPath>
        </dependency>
    • Gradle:

      • Add as a dependency in your build.gradle:
        dependencies {
            implementation files('/path/to/CodeReuse.jar')
        }
  4. Import and Use the CodeReuse Class

    import com.example.CodeReuse;
    
    public class YourClass {
        public static void main(String[] args) {
            int[] array = {4, 2, 7, 1, 9};
    
            // Example for sorting an array
            CodeReuse.sortAscending(array);
            System.out.println("Sorted Array: " + Arrays.toString(array));
    
            // Other method calls as needed
        }
    }

codereuseutility's People

Contributors

fahad-678 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.