Challenge: Name Initials
Completed
Read a first name and a last name (one per line) and print the initials in capital letters, with a dot after each.
Input
Two lines: first name, then last name.
Output
For asha and verma, print A.V.
Example
Input
asha verma
Output
A.V.
Editor
Java
Hints
charAt(0) gives the first character.
Character.toUpperCase(c) makes it a capital.
Start the print with a String so that + joins instead of adding char codes.
Solution explanation
Because a + "." involves a String, Java joins the characters as text. a + b on its own would add their code numbers!
Show solution
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String first = sc.nextLine();
String last = sc.nextLine();
char a = Character.toUpperCase(first.charAt(0));
char b = Character.toUpperCase(last.charAt(0));
System.out.println(a + "." + b + ".");
}
} Output
Answer
You can practice without logging in. Log in to save completion.
Save your progress
You're practising as a guest, so your progress won't be saved.
- Track every lab you complete
- Earn verifiable lab certificates
- See your progress in every module