- Write a function called nameString()
- It should take name as a parameter.
- The function returns a string equal to “Hi, I am” + ” ” + name.
- Call nameString() by passing it your name, and use console. log to print the output.
- const fullName = nameString. split(‘ ‘);
- const initials = fullName. shift(). charAt(0) + fullName. pop(). charAt(0);
- return initials. toUpperCase();
How do you abbreviate names in Java?
This is a really easy one, basically what we will do is the following:
- Convert our name toUpperCase so that we can just pull out the characters we want.
- Convert the name String into 2 separate values, stored in a names array.
- Return the first character of each, using charAt(0) with a dot inbetween.
How do you write a print statement in Java?
In Java, we usually use the println() method to print the statement. It belongs to the PrintStream class. The class also provides the other methods for the same purpose.
Along with this, we will also explain the statement System. out. println().
- print() Method.
- println() Method.
- printf() Method.
You can initialize an array with Array constructor syntax using new keyword. The Array constructor has following three forms. Syntax: var arrayName = new Array(); var arrayName = new Array(Number length); var arrayName = new Array(element1, element2, element3,…
- Use if to specify a block of code to be executed, if a specified condition is true.
- Use else to specify a block of code to be executed, if the same condition is false.
- Use else if to specify a new condition to test, if the first condition is false.