Skip to content

Commit 27d8267

Browse files
committed
refactor: make StackPostfixNotation a proper utility class
1 parent 0a4b299 commit 27d8267

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

src/main/java/com/thealgorithms/others/StackPostfixNotation.java

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
11
package com.thealgorithms.others;
22

3-
import java.util.*;
3+
import java.util.Scanner;
4+
import java.util.Stack;
45

5-
public class StackPostfixNotation {
6-
7-
public static void main(String[] args) {
8-
Scanner scanner = new Scanner(System.in);
9-
String post = scanner.nextLine(); // Takes input with spaces in between eg. "1 21 +"
10-
System.out.println(postfixEvaluate(post));
11-
scanner.close();
6+
public final class StackPostfixNotation {
7+
private StackPostfixNotation() {
128
}
139

1410
// Evaluates the given postfix expression string and returns the result.
15-
public static int postfixEvaluate(String exp) {
11+
public static int postfixEvaluate(final String exp) {
1612
Stack<Integer> s = new Stack<Integer>();
1713
Scanner tokens = new Scanner(exp);
1814

0 commit comments

Comments
 (0)