johnpaulada
10/6/2016 - 3:44 AM

Variables.java

import java.util.Scanner;

public class Variables {
    public static void main(String[] args) {
        
        // int - integer: Can be negative, 0, or positive whole numbers.
        int wholeNumber = 123;
        
        // int[] - An integer array: A collection of integers.
        int[] fibonacci = new int[6];
        
        fibonacci[0] = 0;
        fibonacci[1] = 1;
        fibonacci[2] = 1;
        fibonacci[3] = 2;
        fibonacci[4] = 3;
        fibonacci[5] = 5;
        
        // float - floating point number: A decimal.
        float pi = 3.14;
        
        // double - double precision floating point number: A longer decimal.
        double longerPi = 3.14159;
        
        // char - A single character.
        char letter = 'a';
        
        // char[] - A character array: A collection of characters.
        char[] letters = {'a', 'b', 'c'};
        
        // String - A string of characters: Words, paragraphs, etc.
        String programTitle = "Area Calculator";
        
        // Print the values
        System.out.println(wholeNumber);
        System.out.println(pi);
        System.out.println(longerPi);
        System.out.println(letter);
        System.out.println(letters[0]);
        System.out.println(programTitle);
    }
}