Java: integer variables

This entry is part 5 of 54 in the series Learn Java

In a programming language, the usage of a variable is very similar to variable in Mathematics.  We can assign variable with a particular value.

The example below will make use of 3 variables to to perform a simple mathematical function.

package javaapplication4;

public class JavaApplication4 {

    public static void main(String[] args) {
        int a = 10;
        int b = 15;
        int total;
        total = a + b;

In this program, we first create integers a and b.  We then sum the variables and assign the sum to the variable total.



Series Navigation<< Java: Passing arguments to main
Java: String concatenation >>

Leave a comment

Leave a Reply