Академический Документы
Профессиональный Документы
Культура Документы
System.out.println(text);
Data types
Primitives
Bytes
-128 to 127
Integer 32 bit
-2.147 bil to 2.147 bil
Long 64 bits
-9223 tril to 9223 tril
Float single precision 32 bit
Very big
Double 64 bit
Huge
Double precision floating point
Can handle decimals
Commonly used
Ints and doubles
Char
Short for characters
16 bit Unicode character
Letters, numbers, brackets, periods, etc are all characters
To store an integer
Int y = 3;
Now y is equal to 3
Putting a decimal will make a compiler error, for ex
Int y = 3.2
is the same as
x+=5
similarly,
- x/=5
is the same as
- x=x/5
the same is true for -, and *
this is useful when the names of the variables are long
- mydouble = mydouble-5
takes much longer to type than
- mydouble-=5
Running this will display 12 and 0 since an array automatically assigns a value of 0
to each of its members.
Note: You cannot use keywords as variable names. Some keywords are: false,
true, for and if. Anything in purple is a keyword Also you cannot put numbers
at the beginning of your variable names. Ex. a1423 is a valid variable name but
1232 is not.
For Booleans
public class stuff {
public static void main(String[] args) {
For charaters
import java.util.*;
public class stuff2 {
import java.util.*;
public class stuff2
{
rin.close();
}
First the random.nextInt(5) generates random numbers from the set{0,1,2,3,4} then increments each
by 10 afterwards.