Swan Lake Beta2 is here.
import ballerina/io;

public function main() {
    int m = 1;

    // Integer literals can be hexadecimal (but not octal).
    int n = 0xFFFF;

    // You can use compound assignment operations such as `+=` and `-=`. 
    n += m;

    io:println(n);
}

Integers

The int type is 64-bit signed integers (same as long in Java) and supports the usual arithmetic operators: + - / %. The operator precedence is same as C. Integer overflow is a runtime error in Ballerina.

import ballerina/io;
public function main() {
    int m = 1;
    int n = 0xFFFF;

Integer literals can be hexadecimal (but not octal).

    n += m;

You can use compound assignment operations such as += and -=.

    io:println(n);
}
bal run integers.bal
65536
import ballerina/io;

public function main() {
    int m = 1;

    // Integer literals can be hexadecimal (but not octal).
    int n = 0xFFFF;

    // You can use compound assignment operations such as `+=` and `-=`. 
    n += m;

    io:println(n);
}

Integers

The int type is 64-bit signed integers (same as long in Java) and supports the usual arithmetic operators: + - / %. The operator precedence is same as C. Integer overflow is a runtime error in Ballerina.

import ballerina/io;
public function main() {
    int m = 1;
    int n = 0xFFFF;

Integer literals can be hexadecimal (but not octal).

    n += m;

You can use compound assignment operations such as += and -=.

    io:println(n);
}
bal run integers.bal
65536

In the creation of Ballerina, we were inspired by so many technologies. Thank you to all that have come before us (and forgive us if we missed one): Java, Go, C, C++, D, Rust, Haskell, Kotlin, Dart, TypeScript, JavaScript, Python, Perl, Flow, Swift, Elm, RelaxNG, NPM, Crates, Maven, Gradle, Kubernetes, Docker, Envoy, Markdown, GitHub and WSO2.

Cookie Policy

This website uses cookies so that we can provide you with the best user experience. Read our Cookie Policy to find out more.

If you wish to disable cookies you can do so from your browser.

I Understand