Skip to content

Commit 337453e

Browse files
committed
update 1
0 parents  commit 337453e

File tree

8 files changed

+121
-0
lines changed

8 files changed

+121
-0
lines changed

.classpath

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17">
4+
<attributes>
5+
<attribute name="module" value="true"/>
6+
</attributes>
7+
</classpathentry>
8+
<classpathentry kind="src" path="src"/>
9+
<classpathentry kind="output" path="bin"/>
10+
</classpath>

.project

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>coreJavaPractice</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
</buildSpec>
14+
<natures>
15+
<nature>org.eclipse.jdt.core.javanature</nature>
16+
</natures>
17+
</projectDescription>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
eclipse.preferences.version=1
2+
encoding/<project>=UTF-8
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
eclipse.preferences.version=1
2+
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=17
4+
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
5+
org.eclipse.jdt.core.compiler.compliance=17
6+
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
7+
org.eclipse.jdt.core.compiler.debug.localVariable=generate
8+
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
9+
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
10+
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
11+
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
12+
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
13+
org.eclipse.jdt.core.compiler.release=enabled
14+
org.eclipse.jdt.core.compiler.source=17

bin/coreJavaPractice/Main.class

1.79 KB
Binary file not shown.

bin/module-info.class

155 Bytes
Binary file not shown.

src/coreJavaPractice/Main.java

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
package coreJavaPractice;
2+
3+
import java.util.Stack;
4+
5+
/**
6+
* @author Azo-hub
7+
* @github (https://github.com/Azo-hub)
8+
* @since 2020
9+
*/
10+
public class Main {
11+
12+
public static void main(String [] args) {
13+
/* Reverse Polish Notation
14+
* ["2", "1", "+", "3", "*"] => ((2 + 1) * 3) => 9
15+
* ["4", "13", "5", "/", "+"] => (4 + (13 / 5)) => 6
16+
*/
17+
18+
String[] tokens = {"4", "13", "5", "/", "+"};
19+
System.out.println(evalRPN(tokens));
20+
21+
}
22+
23+
public static int evalRPN(String[] tokens) {
24+
25+
int returnValue = 0;
26+
String operators = "+-*/";
27+
28+
Stack<String> stack = new Stack<>();
29+
30+
for(String t : tokens) {
31+
32+
if(!operators.contains(t)) {
33+
stack.push(t);
34+
} else {
35+
36+
int a = Integer.valueOf(stack.pop());
37+
int b = Integer.valueOf(stack.pop());
38+
39+
/* System.out.print("a: " + a + "and b: " + b); */
40+
41+
switch(t) {
42+
43+
case "+":
44+
stack.push(String.valueOf(b + a));
45+
break;
46+
47+
case "-":
48+
stack.push(String.valueOf(b - a));
49+
break;
50+
51+
case "*":
52+
stack.push(String.valueOf(b * a));
53+
break;
54+
55+
case "/":
56+
stack.push(String.valueOf(b / a));
57+
break;
58+
59+
}
60+
}
61+
}
62+
63+
returnValue = Integer.valueOf(stack.pop());
64+
65+
return returnValue;
66+
}
67+
68+
69+
}
70+
71+
72+

src/module-info.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/**
2+
* @author dell
3+
*
4+
*/
5+
module coreJavaPractice {
6+
}

0 commit comments

Comments
 (0)