Hello, everyone, last time we said is Java function example, this time we say the example is Java synthesis small exercise. Stop gossiping and return to the truth. Let’s Talk Android!

Look at the officers, in front of the chapter back to introduce so many Java content, but did not write a line of code, it is estimated that everyone’s hands are itching, this time, we will introduce the content of the previous comprehensive practice, let everyone start to combat.

public class HelloWorld {

    public static void main(String args[])
    {
        // different type of value
        int intValue = 1;
        long logValue = 1;
        short shotValue = 1;
        byte byteValue = 1;

        float flotValue = 1;
        double dobValue = 1.0;

        char chValue = 'A';
        String strValue = "Hello";

        boolean boolValue = true;

        int array[] = new int[10];

        System.out.println("intValue: "+intValue);     
        System.out.println("logValue: "+logValue);     
        System.out.println("shotValue: "+shotValue);        
        System.out.println("byteValue: "+byteValue);        
        System.out.println("flotValue: "+flotValue);
        System.out.println("dobValue: "+dobValue);     
        System.out.println("chValue: "+chValue);      
        System.out.println("strValue: "+strValue);     

        System.out.println("------------ function------------");
        show(intValue);
        show(logValue);
        show(flotValue);
        show(strValue);
        System.out.println("------------ function------------");

        // change different type of value
// intValue = logValue; // this change is wrong, and it caused a compilation error.
        logValue = intValue;


        //using kinds of operator
        intValue = 1+1;
        System.out.println("Operator + intValue: "+intValue);      

        intValue = 1*9;
        System.out.println("Operator * intValue: "+intValue);      

        intValue += 1;
        System.out.println("Operator += intValue: "+intValue);     

        intValue = 8>>2;
        System.out.println("Operator >> intValue: "+intValue);     

        //using kinds of structure
        if(intValue == 1)
        {
            System.out.println("intValue equals 1");
        }
        else if(intValue < 1)
        {
            System.out.println("intValue is less then 1");
        }
        else
        {
            System.out.println("intValue is larger then 1");
        }

        if(boolValue && intValue > 1)
        {
            System.out.println("boolValue is: "+boolValue);
            System.out.println("intValue is: "+intValue);      
        }

        for(int i=0; i<10; ++i) { array[i] = i+1;
        }

        System.out.print("array: ");
        for(int v:array)
        {
            System.out.print(v+"");
        }
        System.out.println();       

        intValue = 0;
        while(intValue++ < 5) { show(strValue); }}//function overload
    public static void show(int v)
    {
        System.out.println("intValue: "+v);        
    }

    public static void show(long v)
    {
        System.out.println("logValue: "+v);        
    }

    public static void show(short v)
    {
        System.out.println("shotValue: "+v);       
    }

    public static void show(byte v)
    {
        System.out.println("byteValue: "+v);       
    }

    public static void show(float v)
    {
        System.out.println("flotValue: "+v);       
    }

    public static void show(double v)
    {
        System.out.println("dobValue: "+v);        
    }

    public static void show(char v)
    {
        System.out.println("chValue: "+v);     
    }

    public static void show(String v)
    {
        System.out.println("strValue: "+v); }}Copy the code

We use the above code to give a comprehensive demonstration of the previous content. The code belongs to the basic type of code, I believe you can see it, if there is not quite understand the place can refer to the code comments.

The following is the running results of the program, please refer to:

intValue:  1
logValue:  1
shotValue: 1
byteValue: 1
flotValue: 1.0
dobValue:  1.0
chValue:   A
strValue:  Hello
------------ function------------
intValue:  1
logValue:  1
flotValue:  1.0
strValue:  Hello
------------ function------------
Operator + intValue:  2
Operator * intValue:  9
Operator += intValue:  10
Operator >> intValue:  2
intValue is larger then 1
boolValue is: true
intValue is:  2
array:  1  2  3  4  5  6  7  8  9  10  
strValue:  Hello
strValue:  Hello
strValue:  Hello
strValue:  Hello
strValue:  Hello
Copy the code

Everyone see officer, on the Java comprehensive small exercise example we are introduced here, want to know what examples there are behind, and listen to the next decomposition!