Skip to content

August 7, 2014

Define Basic Variables in Java

by admin

In the next example we define basic variables in java. We define an integer, double (floating point number) a boolean and some strings. And then we concatenate two strings in Java. The code is self explanatory.

package learnjava01;
 
public class Learnjava01 {
 
    public static void main(String[] args) {
        int a = 10;
        double b = 20.0;
        boolean isTrue = true || false && true || true;
        System.out.println(a+b);
        System.out.println(isTrue);
 
        boolean isTrue2 = 4.1 >=4;
        System.out.println(isTrue2);
 
        // concatenate strings
        String str1 = "the quick fox ";
        String str2 = "jumped over the lazy dog";
        System.out.println(str1+str2);
 
        int m = 20;
        String str3 = "his age is " + m + " years old";
        System.out.println(str3);
    }   
}
Read more from Java Examples

Leave a Reply

required
required

Note: HTML is allowed. Your email address will never be published.

Subscribe to comments