We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
public class Solution {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int N = scanner.nextInt(); // Number of rows
scanner.nextLine(); // Consume newline
List<String> names = new ArrayList<>();
for (int i = 0; i < N; i++) {
String[] data = scanner.nextLine().split(" ");
String firstName = data[0];
String emailID = data[1];
// Check if the email ends with "@gmail.com"
if (emailID.endsWith("@gmail.com")) {
names.add(firstName);
}
}
// Sort names alphabetically
Collections.sort(names);
// Print sorted names
for (String name : names) {
System.out.println(name);
}
scanner.close();
}
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Day 28: RegEx, Patterns, and Intro to Databases
You are viewing a single comment's thread. Return to all comments →
import java.util.*;
public class Solution { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int N = scanner.nextInt(); // Number of rows scanner.nextLine(); // Consume newline
}