Basic Types
While there are numerous variable types in Java, here are the five most critical types used in FTC.
- int
- float
- double
- string
- boolean
Integer
The int variable holds a numerical value that can be accessed when called upon. It can hold integers or whole numbers.
int inchCount;
inchCount = 6;
Float
The float variable is used to represent numbers that have a decimal place in them. It is similar to the int variable type, but can hold up to 7 digits of precision.
float decimal = (float) 3.2;
float d = 3.2f;
Double
The double variable is more precise than the float variable type because this type of variable can hold up to 16 digits of precision.
double numeral = 5.6;
numeral = 2.4;
String
A string variable is used to show a line of text, numbers, or symbols.
String message1 = new String("This is how to write a string!");
String message2 = "Wow this is amazing!";
Boolean
A boolean variable basically tells if an instance is true or false. For example, if one action is deemed true, then it will carry out a specific action.
boolean value = true;
if (value == true) {
System.out.println("this is true");
} else {
System.out.println("this is false");
}