Java Program You will be given the source and destination of all the tickets in the form of a map, and you have to print

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

Java Program You will be given the source and destination of all the tickets in the form of a map, and you have to print

Post by answerhappygod »

Java Program
You will be given the source and destination of all the tickets
in the form of a map, and you have to print the itinerary from all
those tickets.
Note:
Input: The input will be in the following
format:
Output: The output should be in the following
format
Sample test case 1:
Input:
Output:
Sample test case 2:
Input:
Output:
Sample test case 3:
Input:
Output:
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class Source {
public static void main(String[] args) {
Scanner in = new
Scanner(System.in);
// get the no of tickets from
input
int n = in.nextInt();
// map to store all the
tickets
Map<String, String> tickets = new
HashMap<String, String>();
// Store the source and destination
of the tickets to the map "tickets"
for (int i = 0; i < n; i++) {
tickets.put(in.next(),
in.next());
in.nextLine();
}
// write your code here

}
}
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply