Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

import java.util. * ; public class LookupMultipleNumber { public static void main ( String [ ] args ) { Scanner in = new Scanner (

import java.util.*;
public class LookupMultipleNumber {
public static void main(String[] args){
Scanner in = new Scanner(System.in); // Use Scanner for standard input
int maxRes = Integer.parseInt(args[1]);
int keyField = Integer.parseInt(args[2]);
int valField = Integer.parseInt(args[3]);
Map> map = new LinkedHashMap<>();
while (in.hasNextLine()){
String line = in.nextLine();
String[] tokens = line.split(",");
String key = tokens[keyField];
String val = tokens[valField];
map.putIfAbsent(key, new LinkedList<>());
map.get(key).add(val); // Use add for Queue
}
Scanner stdin = new Scanner(System.in); // New Scanner for standard input
while (stdin.hasNext()){
String s = stdin.next();
if (!map.containsKey(s)){
System.out.println("null");
} else {
int i =0;
for (String value : map.get(s)){
System.out.print(value +"");
i++;
if (i == maxRes){
break;
}
}
System.out.println();
}
}
in.close();
stdin.close();
}
}
MSample runs would be as follows (refer to input file amino.csv).
>java LookupMultipleNumber amino.csv 230
Tryptophan
TGG
Cysteine
TGT TGC

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems A Practical Approach To Design Implementation And Management

Authors: THOMAS CONNOLLY

6th Edition

9353438918, 978-9353438913

More Books

Students also viewed these Databases questions

Question

What Is acidity?

Answered: 1 week ago

Question

Explain the principles of delegation

Answered: 1 week ago

Question

State the importance of motivation

Answered: 1 week ago

Question

Discuss the various steps involved in the process of planning

Answered: 1 week ago

Question

What are the challenges associated with tunneling in urban areas?

Answered: 1 week ago

Question

Why do HCMSs exist? Do they change over time?

Answered: 1 week ago