Binge watching, Java Basics
String concatenation:
today = 4;
total = 100;
System.out.println("Day "+today+" of "+total+" - Learning Java");
Points:
- Use lower camel case for variable names.
- use full names. speed instead of sp;
- Start variable with a letter. var8 or v1 and not 8var
- Long or Integer for integer values. Double for fractions
-
String or Character datatypes. Character cannot be used for calculations
String text = "(a) Today is January 12 2022"; char hello = '4'; char three = '3'; //char ten = '10'; // Cannot store more than one letter.
-
boolean
//boolean hello = 21; //incorrect boolean hello = true; // long number = 100.1; // only natural numbers
-
Variable Arithmetic
int negNumber = -20; // =-20 int multNumber = 5*6; // = 30 // double divide = 5/2; //=2 double divide2 = 24/5; //not 4.8, =4 double accurateDivide = 5/2.0; // 2.5 // int x = 2+3; //5 int y = 4-5; //-1 int z = x*y; //-5 // double paid = 10; double change = 3.25; double tip = (paid-change)*0.2; // double tip = paid - change * 0.2;
If in doubt, use parentheses ().
*
or/
before+
or-
.-
Casting
double div = 5/2; System.out.println(div);//2 double accurateDiv = (double)x/y; System.out.println(accurateDiv);
Top comments (0)