Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Onp2 {
- public static void main(String[] args) {
- int j = 0;
- String[] stack = new String[10];
- int stackPosition = -1;
- for(String str: args)
- {
- stack[j] = "";
- if(str.endsWith("=")){
- for(int i=0; i< str.length(); i++)
- if(str.charAt(i) >= '0' && str.charAt(i) <= '9' || str.charAt(i) == '.'){
- stack[++stackPosition] = str.charAt(i) + " ";
- //if(!(str.charAt(i+1) >= '0' && str.charAt(i+1) <= '9' && str.charAt(i+1) == '.'))
- //stack[stackPosition] += " ";
- }
- else{
- switch(str.charAt(i)){
- case '-':
- case '+':{
- stack[--stackPosition] = "( " + stack[stackPosition] + str.charAt(i) + " " + stack[stackPosition+1] + ")";
- break;
- }
- case '*':
- case '/':
- case '^':
- stack[--stackPosition] = stack[stackPosition] + str.charAt(i) + " " + stack[stackPosition+1];
- break;
- default:
- break;
- }
- }
- }
- else
- System.out.println(str + ": Bledne rownanie");
- System.out.println(args[j]);
- System.out.println(stack[j]);
- j++;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement