Codingame Solution : optimalChange JAVA

I was asked to create a method that would: Return a Change object or null if there was no possible change The “machine” has unlimited bills of: 2, 5 and 10 The Change object must return the most minimal amount of bills possible Implement the optimalChange(long s) method ! Solution : Read also : Solution […]

En Lire Plus

Codingame Solution : reshape Java

Reshape Java : The reshape(n, str) method should return the string str without spaces and layed out in lines of at most n characters.     Examples:     reshape(3, “abc de fghij”) => returns “abc\ndef\nghi\nj”     reshape(6, “1 23 456”) => returns “123456” Solution : Read also : IsTwin Codingame problem

En Lire Plus

Codingame solution : closestToZero JAVA

Question Implémentez la méthode closestToZero pour renvoyer l’entier du tableau ints le plus proche de zéro. S’il y a deux entiers tout aussi proches de zéro, considérez l’entier positif comme étant le plus proche de zéro (par exemple si ints contient -5 et 5, retournez 5). Si ints est null ou vide, retournez 0 (zero). […]

En Lire Plus

What does mean Serialization and Deserialization in Java ?

Serialization is a mechanism of converting the state of an object into a byte stream. Deserialization is the reverse process where the byte stream is used to recreate the actual Java object in memory. This mechanism is used to persist the object. java.io.Serializable interface The next example show how to apply this in object class […]

En Lire Plus

Les Bases du langage JAVA [FR]

Introduction Au début des années 90, Sun travaillait sur un projet visant à concevoir des logiciels simples et performants exécutés dans des PDA (Personnal Digital Assistant). Le langage C++ a été retenu pour la programmation de ces logiciels, mais le langage C s’est avéré peu performant , notamment en ce qui concerne la sécurité et […]

En Lire Plus

Java : How to Convert Integer to Binary

In Java, we can use Integer.toBinaryString(int) to convert an Integer to a binary string representative. This article will show you two methods to convert an Integer to a binary string representative. JDK Integer.toBinaryString. Old school bit masking technique. 1. Convert Int to Binary Integer.toBinaryString 1.1 This Java example tries to convert an int to a binary string […]

En Lire Plus

Java : How to Convert Character to ASCII

In Java, we can cast the char to int to get the ASCII value of the char. The explicit cast (int)char is optional, if we assign a char to an integer, Java will auto-cast the char to an int. 1. Convert Char to ASCII This Java example converts a char to an ASCII value, and […]

En Lire Plus

Java vs Python

…most people treat me like idiot for using my head instead of learning 3000 of them for each possible problem. And you’ve hit the nail on the head right there! I concur. The trouble is, almost all Java-related documentation, courses, guides, tutorials, and answers I see advocate certain design patterns, code snippets, and habits (a […]

En Lire Plus

Java : how to convert negative binary to Integer ?

Review the following Java example to convert a negative integer in binary string back to an integer type. The result is NumberFormatException ! The NumberFormatException is due to overflow, the string 11111111111111111111111111111111 (length of 32) are unable to fit into the 32 bits int type ? Note Note Integer has values from -2^31 to 2^31-1 […]

En Lire Plus

Java 15 in 2020

In 2020, Java 15 will be released with major features (some coming out of preview mode), both at language, API, and runtime levels. https://openjdk.java.net/projects/jdk/15/ Considering the changes that have already made through since Java 8 and the upcoming changes in Java 15, what are in your opinion the use cases that no longer make sense […]

En Lire Plus

“Auto increment” alphabet in Java ?

Auto increment alphabet in Java : There is two solution for auto increment alphabet using java : Solution 1 : Solution 2 : It is also possible with typecasting Read also : Java 7 – Java 8 – loop Map / List – forEach examples Read also : Twitter teste une façon de limiter les […]

En Lire Plus

Java : multi-line string, text blocks

Java multi-line string text blocks : This article will show you a few ways to declare and use a multi-line string in Java. String + String + String StringBuilder String.format StringWriter String.join (Java 8) Files.lines (Java 8) (“””) Java 13 and Java 14 text blocks (preview feature) Java multi-line string text blocks : Review an […]

En Lire Plus

Switch Expressions in Java 13

Switch Expressions in Java 13 : In Java 13, the JEP 354: Switch Expressions extends the previous Java 12 Switch Expressions by adding a new yield keyword to return a value from the switch expression. P.S Switch expressions are a preview feature and are disabled by default. 1. No more value breaks! 1.1 Java 12 value breaks syntax is no longer […]

En Lire Plus