String fullName;
fullName = "Michael Mortimer Maus";
An assignment statement has this form.
variable = expression;
Where expression can be one of the following:
fullName = "Brenda Begoode";
fullName = nameEntered;
fullName = JOptionPane.showInputDialog(null, "Enter your name - or else!");
byte, short, int, longint for integer variables.int range is -2147483648 to +2147483647 .int age; age = 24;
float, doubledouble for floating-point variables.double range is about +/- 10308.double precision is about 15 significant digits.double temperature; temperature = 65.377;
It's possible to declare more than one variable in the same declaration.
double height, weight;
But I would prefer that you put them in separate declarations. It makes documenting them easier, and avoids errors in certain cases.
double height; // Height in centimeters. double weight; // Weight in kilograms.
Before you can use a variable, you have to declare it and initialize it.
String fullName; fullName = "nobody";
It is common to initialize a variable in the declaration.
String fullName = "nobody";
+) 8 + 3 is 11-) 8 - 3 is 5*) 8 * 2 is 16/) 8 / 2 is 4%) 5 % 3 is 23 / 2 is 1, not 1.5
a + b * c is a + (b * c)
String s;
s = "abc" + "def"; // same as s = "abcdef";
s = "abc" + 4; // same as s = "abc4"
s = "abc" + (3 + 4); // same as s = "abc7"
s = "abc" + 3 + 4; // same as s = "abc34"
String s1 = "goodbye"; String s2; int i;
s2 = s1.substring(0,3); // same as s2 = "goo"
s2 = s1.substring(1, 5); // same as s2 = "oodb"
i = s1.length(); // same as i = 7
s2 = s1.substring(i-1, i); // last char in s1 (assuming i=s1.length()
i = s1.indexOf("b"); // same as i = 4
i = s1.indexOf("bye"); // same as above
i = s1.indexOf("B"); // i = -1 Uppercase not same as lowercase.