Chapter java learning

1. Variable
variable constants can be changed is,
for example: int represents the integer type can store data type. int a; that you define a variable to store integers. a variable is your name; int a = 10; mean that you give this variable is assigned a value of 10; you execute this code, int a = 10; the program will in your computer's memory, to create a small space, the name of this space is a, this is the space inside the contents of 10, this space can only store integer data types.

2. Definition of variable names
begin with the variable name must be a letter or an underscore, not a number. Usually nomenclature with a large or a small hump hump nomenclature. But is not the variables in Java keywords, such as: public class printf goto if so forth.
3. The first Java program

public class hello {

	public static void main(String[] args) {
		
System.out.println("Hello World!");
	}
}

First, we define a class, and then create the main function, we use our command line to compile.
Enter in the operation cmd, and then into the black box, cd into the directory of our Java programs, and then we enter the file name .Java javac compile, compile if successful, will generate a .class file, we export java class file name run the program. Then we can see the results of running the program:

Hello World!

4. Type conversion operations
1) by accuracy from low to high

2) high accuracy low intensity conversion value assigned to the precision necessary :( type name) to convert

public class Demo01DateType{
  public static void main(String[] args){
    System.out.println(1024);
    System.out.println(3.14);
    
    // 左边的是long类型,右边的是int类型
    // int类型转为long类型,符合范围从小到大
    long num1 = 100;
    System.out.println(num1);
    
    // 左边的double类型, 右边的是float
    // float转为double类型,符合范围从小到大
    double num2 = 2.5F;
    System.out.println(num2);
    
    // 左边的是float类型,右边的是long类型
    // long类型数据转为float数据,符合范围从小到大
    float num3 = 10L;
    System.out.println(num3);
  }
}

5.Java output

System.out.println()
System.out.print()

The first wrap is output after
the output of the second line do not change

Published 11 original articles · won praise 0 · Views 261

Guess you like

Origin blog.csdn.net/yihjh/article/details/104185632