Giter Site home page Giter Site logo

meanmail / java_base Goto Github PK

View Code? Open in Web Editor NEW
28.0 28.0 20.0 432 KB

Java. Базовый курс на stepik.org. Тесты для задач.

Home Page: https://stepik.org/course/Java-Базовый-курс-187

License: GNU General Public License v3.0

Java 100.00%
java stepik stepik-plugin stepik-tests stepik-union

java_base's Introduction

java_base's People

Contributors

meanmail avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

java_base's Issues

MergeArrays

Failed test #5. Run time error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1
at Main.mergeArrays(Main.java:65)
at Main.main(Main.java:29)
at Main.main(Main.java:9)

public static int[] mergeArrays(int[] a1, int[] a2) {

    if (a1.length == 0) {
        return a2;
    } else if (a2.length == 0) {
        return a1;
    }

    int max_len;
    int min_len;
    if (a1.length >= a2.length) {
        max_len = a1.length;
        min_len = a2.length;
    } else {
        max_len = a2.length;
        min_len = a1.length;
    }
    int[] arr = new int[max_len + min_len];
    int i = 0, j = 0, k = 0;

    while (i < max_len && j < max_len && k < (max_len + min_len)) {
        if (j < a2.length && k < (max_len + min_len) && a1[i] >= a2[j]) {
            arr[k] = a2[j];
            ++j;
            ++k;
        } else if (  i < a1.length && k < (max_len + min_len) && a1[i] < a2[j]) {
            arr[k] = a1[i];
            ++i;
            ++k;
        }
    }


    while (i < a1.length && k < (max_len + min_len)) {
        arr[k] = a1[i];
        ++i;
        ++k;
    }

    while (j < a2.length && k < (max_len + min_len)) {
        arr[k] = a2[j];
        ++j;
        ++k;
    }

    return arr; // your implementation here
}

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.