Skip to content

java_task

Achievement unlocked. Sololearn Java certificate.

Sololearn Java course

Yesterday I finished a Java course with the Sololearn iPhone appilcation. Just for fun. I had some free time and decided, why not to study Java on my mobile phone, so that’s how I found this app. What can I say about it? It gives very little knowledge about Java.

There are 6 sections in this course: basic concepts, conditionals and loops, arrays, classes and objects, more on classes, and the last one, exceptions, lists, threads and files. Each section contain a small piece of theory and some ordinary practical tasks. I wonder, how have developers decided to combine such large themes as collections and threads (and exceptions and files)?

I don’t know what’s the target audience of this app. If you’re a beginner, you probably shouldn’t download it, because it’d be better to read some good Java books. The application can’t give you even 1/10 of needed knowledge. If you have some Java experience, you probably won’t discover anything new.

My mark: ❤️❤️❤️💙💙💙💙💙💙💙

Programming competition and a small Java task

Last week we had a programming competition at work which consisted of some small tasks. One of them was to check, if we can make a given string palindrome by adding one letter in any place. Shame on me, I didn’t manage with this task in time. However I got the third place in this competition. 🏆😁

So the task:
Your app should check, if it’s possible to make a palindrome by adding a lowercase English letter to a given string in any position. If it is, the application should return an index which points to where to put a character, otherwise the app should return -1.
The given string contains only lowercase Latin characters.

What is a palindrome? Palindrome is a word or a number, which reads the same backward and forward. For example:

  • Was it a car or a cat I saw?
  • 1234321
  • Step on no pets

See the solution.

Read More →

Java task. Fibonacci sequence.

Fibonacci numbers are a number sequence, where first two numbers are 1 and 1 or 0 and 1. Each subsequent number is the sum of previous two numbers. This task is often asked by interviewers (not only in Java). Let’s solve it in two ways: using a loop and recursion.

public int getFibonacci(int number) {
    if (number == 1 || number == 2) {
        return 1;
    }
		
    int fibo1 = 1;
    int fibo2 = 1;
    int fibonacci = 1;
		
    for (int i = 3; i <= number; i++) {
        fibonacci = fibo1 + fibo2;
        fibo1 = fibo2;
        fibo2 = fibonacci;
    }

    return fibonacci;
}

To see a recursive solution of this task, click “read more”.

Read More →