String firstName;
String lastName;
int minute, hour;
firstName = "Mark Anthony";
lastName = "Degamo";
minute = 59;
hour = 12;
Java's reserved words includes: public, private, static, void and many more. See the full list here.
Use the + operator.
Example:
System.out.println("Hello" + " World");The syntax for typecasting is to put the name of the type in parentheses and use it as an operator.
Example:
double pi = 3.14159;
int x = (int) pi;
Use the void keyword.
public static void doSomething() {
// do something here
}Declare the return type of the method. In this case we'll return the combined name which is a String.
public static String combineName(String firstName, String lastName) {
return firstName + " " + lastName;
}int[] nums = new int[]{1, 2, 3, 4, 5};
for (int i: nums) {
System.out.println(i);
}You can't. You need to keep track of the index.
int[] nums = new int[]{1, 2, 3, 4, 5};
int index = 0;
for (int i: nums) {
System.out.println(index + ": " + i);
index++;
}To compare Strings, we have to use the equals and compareTo methods. For example:
String name1 = "Alan Turing";
String name2 = "Ada Lovelace";
if (name1.equals (name2)) {
System.out.println("The names are the same.");
}Use Arrays.toString(arr) or Arrays.deepToString(arr) from java.util.Arrays.
int[] intArray = new int[] {1, 2, 3, 4, 5};
String[] strArray = new String[] {"John", "Mary", "Bob"};
System.out.println(Arrays.toString(intArray));
System.out.println(Arrays.toString(strArray));OlderNewer