Advertisement
Talar97

Sprawdzanie poprawności wyrazenia w postaci postfiksowej

Mar 27th, 2018
313
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.58 KB | None | 0 0
  1. boolean sprawdzPoprawnosc(String lancuch){
  2.         boolean wynik = false;
  3.         int operatory = 0;
  4.         int zmienne = 0;
  5.         for(int i = 0; i < lancuch.length(); i++){
  6.             if(lancuch.charAt(i) == '+' || lancuch.charAt(i) == '-' || lancuch.charAt(i) == '*' || lancuch.charAt(i) == '/') operatory++;
  7.             if(Character.isLetter(lancuch.charAt(i))) zmienne++;
  8.         }
  9.  
  10.         if((operatory+1)==zmienne) wynik = true;
  11.         else wynik = false;
  12.  
  13.         System.out.println("operatory: "+operatory + ", zmienne:" + zmienne);
  14.  
  15.         return wynik;
  16.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement