smgr

Karakter metódusok

Feb 13th, 2013
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.30 KB | None | 0 0
  1. public class charMethods {
  2.     public static void main(String [] args){
  3.        
  4.         char [] betuk = {'a','e','m','a','z','i','u','u','u','i','o'};
  5.        
  6.         //System.out.println(elofordul("uzi", betuk));
  7.  
  8.         //howMany(betuk);   // 6
  9.  
  10.         System.out.println(tavolsag('a','i',betuk));
  11.        
  12.     }
  13.    
  14.     /*static void howMany(char [] chars){
  15.         char [] tmp = new char [chars.length];
  16.         int n=0;
  17.         for(int i=0; i<chars.length; i++)
  18.             for(int j=0; j<tmp.length; j++)
  19.                 if(tmp[j] == chars[i]) {
  20.                     break;
  21.                 }
  22.                 else {
  23.                     tmp[n++] = chars[i];
  24.                     break;
  25.                 }
  26.         for(int i=0; i<tmp.length; i++)
  27.             System.out.println(tmp[i] + ": ");
  28.     }*/
  29.    
  30.     /*static boolean elofordul(String szo, char[] chars){
  31.         boolean tmp [] = new boolean [szo.length()];
  32.         int n=0;
  33.         boolean ered = false;
  34.         for(int i=0; i<chars.length; i++)
  35.             for(int j=0; j<szo.length(); j++)
  36.                 if( chars[i]==szo.charAt(j) )
  37.                     tmp[n++] = true;
  38.         for(int i=0; i<tmp.length; i++)
  39.             if(tmp[i] == false)
  40.                 ered = false;
  41.         return ered;
  42.     }*/
  43.    
  44.     static int tavolsag(char a, char b, char [] array){
  45.         int aHely = 0;
  46.         int bHely = 0;
  47.         for(int i=0; i<array.length; i++)
  48.             if(array[i] == a){
  49.                 aHely = i;
  50.                 break;
  51.             }
  52.         for(int i=aHely; i<array.length; i++)
  53.             if(array[i] == b){
  54.                 bHely = i;
  55.                 break;
  56.             }
  57.         return bHely-aHely;
  58.     }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment