The following was a question I needed to understand for my course. How to enter the command
Question:
The following was a question I needed to understand for my course. How to enter the command line argument in eclipse to receive the requested output.
import java.util.*;
import java.io.*;
public class LineNum {
public static void main(String[] args) throws Exception{
int n = Integer.parseInt(args[0]);
Queue myQueue = new LinkedList<>();
String data="";
BufferedReader keyBorad = new BufferedReader(new InputStreamReader(System.in));
String line;
while((line = keyBorad.readLine()) != null) {
myQueue.add(line); //adding element to the queue
}
if(n > myQueue.size()){
System.out.println("Queue contains less than "+n+" items.");
return;
}
for(int i=0 ; i< n ;i++){
data = myQueue.remove(); //removing element from the queue
}
System.out.println(n+ " from the first is "+data);
}//end of main() method
}//end of class LineNum
- Sample runs would be as follows.
- >java LineNum 2
- apple
- save
- that
- is
- too
- me
- 2 from the first is save
- >java LineNum 3
- this
- is
- not
- a
- shorter
- version
- 3 from the first is not
Income Tax Fundamentals 2013
ISBN: 9781285586618
31st Edition
Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill