Friday, March 2, 2012

How to declare variables?

    i love IT.
variables, These are elements of a program that  will hold values that will be declared within. There are different primitive data types in java like String, int, double etc.

public class Variables {
    public static void main(String[] args) {
        String stringAko="eto ay string type variable";   //double quotation is needed in string output
        int numero=12;   //must have no   quotations
        double mayDecimal=12.12;   //double  use for decimals
          
           /*any variable name(stringAko,numero,mayDecimal)
              is valid  as long as it is easy to understand*/
        
        System.out.println(stringAko);   //the value of the variable name will be printed
        System.out.println(numero);  //same
        System.out.println(mayDecimal);  //same
    }
}


Output:

eto ay string type variable
12
12.12

More examples by request,
More lessons to come.
If you have more something to add that will be highly appreciated
SHARE and LEARN!

No comments:

Post a Comment