Advertisement
Guest User

Example3_strpos

a guest
Jun 23rd, 2017
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.49 KB | None | 0 0
  1.  
  2. public class Example3 {
  3.     private int strpos(String text, char z) {
  4.         boolean j = true; // sprawdza czy było przynajmniej jedno wystąpienie
  5.         for (int i = 0; i < text.length(); i++) {
  6.             if (text.charAt(i) == z) {
  7.                 System.out.println(i + 1);
  8.                 j = false;
  9.             }
  10.         }
  11.         if (j == true)
  12.             return -1;
  13.         else
  14.             return 1; // bo musi coś zwrócić
  15.     }
  16.  
  17.     public static void main(String[] args) {
  18.         Example3 s = new Example3();
  19.         System.out.println(s.strpos("belzebub", 'b'));
  20.     }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement