Question: JAVA Please read carefully. Thanks ****************************************** Question 1: StackOfStrings s = new StackOfStrings(); while (!StdIn.isEmpty()) { String item = StdIn.readString(); if (!item.equals(-)) s.push(item); else if
JAVA Please read carefully. Thanks
******************************************
Question 1:
StackOfStrings s = new StackOfStrings(); while (!StdIn.isEmpty()) { String item = StdIn.readString(); if (!item.equals("-")) s.push(item); else if (s.isEmpty()) StdOut.println("BAD INPUT"); else StdOut.print(s.pop() + " "); } Suppose the input is " one two three - four five - - six - seven " What would be the second word in the output?
Question 1 options:
| two | |
| four | |
| six | |
| none of these |
Question 2:
Consider the code segment below:
Node x = new Node(2); Node a = new Node(3); Node c = new Node(4); Node b = new Node(7); x.next = a; c.next = x; b.next = c;
If we print the list starting at x, the result would be:
Question 2 options:
| 7 3 2 4 | |
| 7 3 2 | |
| 7 4 2 3 | |
| none of these |
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
