1. The number of switching two basics 2. Determining the maximum and minimum values of the variable 3

A. Exchanging two numbers
Here Insert Picture Description
two. Given three numbers, seeking the maximum and minimum
Here Insert Picture Description
three basic knowledge variables.
1. integer variable int

int num = 10;
system.out.println(num);

In Java, an int variable is four bytes and operating systems not directly related to the range of 4 bytes of data is -2 ^ 31 -> 2 ^ 31-1, it is about -21 billion and + 2.1 billion. in order to express more data, java provides a long type.
2. long long integer variable

long num = 10L;
system.out.println(num);	

Java, 8 bytes long type of data represented by the range -2 ^ 63 -> 2 ^ 63-1, far beyond an int.
3. The double-precision floating-point variables double

double num = 1.0;
system.out.println(num);

Although the Java double is 8 bytes, but the great difference between the integer and floating point memory layout of the data can not be simply represented by a range of 2 ^ n form. Java memory layout of a double standard IEEE 754 compliance (C and languages), try to use the limited memory space may be infinite decimal representation, there is bound to be a certain degree of accuracy error.
4. single-precision floating-point variables

float num = 1.0F;
system.out,println(num);

fl oat type accounted for four bytes in Java, also comply with the IEEE 754 standard. Due to the small data accuracy range indicated generally use floating-point numbers are priorities double, do not recommend the use of fl oat on the project.
The character type variable

char = 'A';
system.out,println(num);

In java, you can use a character representation of a character such as: char = 'ah'; NOTE: The error may occur while performing, so we should javac time,
plus utf8 the -encoding.
6. byte type variable

byte value = 0;
system.out,println(value);

Byte integer type is represented by only one byte, represents a smaller range (-128 -> +127)., And the type byte character type unrelated
7. short integer variable

short  value = 0;
system.out.println(value);

short occupies 2 bytes, the data range indicated -32768 -> 32767 2. This represents the range of relatively small, generally not recommended
8. boolean variable

boolean value = ture;
system.out.prinln(value);

boolean type of variable only two values, true for true, false false representation. Java's boolean type int and can not be converted to each other, there is no 1 for true, 0 for such usage false. boolean achieve some type of JVM is accounted for 1 bytes, some of which are accounted for a bit, this is not clearly defined.
9. string variable type
some characters are put together to form the string

String name = "zhangsan";
System.out.println(name);

Java several characters in double quotes + represents manner string literals. Above different types, String not a basic type, but the reference type.
String operation + represents string concatenation, and the string may be an integer splice.
Here Insert Picture Description

Published 60 original articles · won praise 23 · views 3330

Guess you like

Origin blog.csdn.net/weixin_44945537/article/details/101065261