Here's the modified code that allows the user to enter 10 integers from the keyboard, stores odd numbers in the oddStack, stores even numbers in the evenStack, and then traverses and displays both stacks in LIFO (Last In, First Out) order.
```java
import java.util.Scanner;
public class StackLL {
public static void main(String[] args) {
StackType oddStack = new StackType();
StackType evenStack = new StackType();
Scanner scanner = new Scanner(System.in);
System.out.println("Enter 10 integers:");
for (int i = 0; i < 10; i++) {
int num = scanner.nextInt();
if (num % 2 == 0) {
evenStack.push(num);
} else {
oddStack.push(num);
}
}
System.out.println("Odd Stack (LIFO):");
while (!oddStack.isEmpty()) {
System.out.println(oddStack.top());
oddStack.pop();
}
System.out.println("Even Stack (LIFO):");
while (!evenStack.isEmpty()) {
System.out.println(evenStack.top());
evenStack.pop();
}
scanner.close();
}
// A linked list node
static class Node {
int data; // integer data
Node next;
}
// Stack class
static class StackType {
Node stackTop;
// Default constructor
StackType() {
this.stackTop = null;
}
// Utility function to check if the stack is empty or not
public boolean isEmpty() {
return (stackTop == null);
}
// Utility function to push an element to the stack
public void push(int x) {
Node node = new Node();
node.data = x;
node.next = stackTop;
stackTop = node;
}
// Utility function to return the top element in the stack
public int top() {
if (!isEmpty())
return stackTop.data;
else
throw new IllegalStateException("Stack is empty");
}
// Utility function to pop the top element from the stack
public void pop() {
if (!isEmpty())
stackTop = stackTop.next;
else
throw new IllegalStateException("Can not pop an empty stack");
}
}
}
```
This code prompts the user to enter 10 integers, stores odd numbers in the `oddStack`, even numbers in the `evenStack`, and then traverses and displays both stacks in LIFO order.
Note: Make sure to import the necessary packages and add any additional error handling or validation as per your requirements.