Naloga 1
This commit is contained in:
parent
eb45bf0c2b
commit
5c6b052298
@ -1,19 +1,14 @@
|
|||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
public class Naloga1 {
|
public class Naloga1 {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) throws CollectionException {
|
||||||
Calculator calculator;
|
Calculator calculator = new Calculator();
|
||||||
try {
|
|
||||||
calculator = new Calculator();
|
|
||||||
|
|
||||||
Scanner scanner = new Scanner(System.in);
|
Scanner scanner = new Scanner(System.in);
|
||||||
while (scanner.hasNextLine()) {
|
while (scanner.hasNextLine()) {
|
||||||
calculator.reset();
|
calculator.reset();
|
||||||
String line = scanner.nextLine();
|
String line = scanner.nextLine();
|
||||||
calculator.run(line);
|
calculator.run(line);
|
||||||
}
|
|
||||||
} catch (CollectionException e) {
|
|
||||||
System.out.println(e.getMessage());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -235,7 +230,7 @@ class Calculator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void len() throws CollectionException {
|
void len() throws CollectionException {
|
||||||
mainStack.push(String.valueOf(mainStack.pop().length()));
|
pushInt(mainStack.pop().length());
|
||||||
}
|
}
|
||||||
|
|
||||||
void neq() throws CollectionException {
|
void neq() throws CollectionException {
|
||||||
@ -270,32 +265,38 @@ class Calculator {
|
|||||||
|
|
||||||
void sub() throws CollectionException {
|
void sub() throws CollectionException {
|
||||||
int right = popInt();
|
int right = popInt();
|
||||||
pushInt(popInt() - right);
|
int left = popInt();
|
||||||
|
pushInt(left - right);
|
||||||
}
|
}
|
||||||
|
|
||||||
void mul() throws CollectionException {
|
void mul() throws CollectionException {
|
||||||
pushInt(popInt() * popInt());
|
int right = popInt();
|
||||||
|
int left = popInt();
|
||||||
|
pushInt(left * right);
|
||||||
}
|
}
|
||||||
|
|
||||||
void div() throws CollectionException {
|
void div() throws CollectionException {
|
||||||
int right = popInt();
|
int right = popInt();
|
||||||
pushInt(popInt() / right);
|
int left = popInt();
|
||||||
|
pushInt(left / right);
|
||||||
}
|
}
|
||||||
|
|
||||||
void mod() throws CollectionException {
|
void mod() throws CollectionException {
|
||||||
int right = popInt();
|
int right = popInt();
|
||||||
pushInt(popInt() % right);
|
int left = popInt();
|
||||||
|
pushInt(left % right);
|
||||||
}
|
}
|
||||||
|
|
||||||
void concat() throws CollectionException {
|
void concat() throws CollectionException {
|
||||||
String right = mainStack.pop();
|
String right = mainStack.pop();
|
||||||
mainStack.push(mainStack.pop() + right);
|
String left = mainStack.pop();
|
||||||
|
mainStack.push(left + right);
|
||||||
}
|
}
|
||||||
|
|
||||||
void rnd() throws CollectionException {
|
void rnd() throws CollectionException {
|
||||||
int y = popInt();
|
int y = popInt();
|
||||||
int x = popInt();
|
int x = popInt();
|
||||||
pushInt((int) (Math.random() * (y - x + 1) + x));
|
pushInt((int) Math.round(Math.random() * (y - x) + x));
|
||||||
}
|
}
|
||||||
|
|
||||||
void then() throws CollectionException {
|
void then() throws CollectionException {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user