I was trying to implement a java program to process user input from command line.The problem was one given in Algorithms book (sedgewick)
1.1.21 Write a program that reads in lines from standard input with each line contain- ing a name and two integers and then uses printf() to print a table with a column of the names, the integers, and the result of dividing the first by the second, accurate to three decimal places. You could use a program like this to tabulate batting averages for baseball players or grades for students.
I tried to implement this as follows..but I am stuck in storing the user input sothat it can be printed using printf() ..I thought Scanner would be appropriate for getting the user input..Still I can't seem to get the input stored for later use.
The class Stack is from sedgewick's book.
Any idea how to get this right?
Scanner input = new Scanner(System.in);
Stack st = new Stack();
while(input.hasNext()){
String tkn = input.next();
st.push(tkn);
if (st.size()==3){
int y = Integer.parseInt((String)st.pop());
int x = Integer.parseInt((String)st.pop());
String name = (String)st.pop();
System.out.println("name="+name+",x="+x+",y="+y);
}
}