can i do this in a loop?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • metalinc
    New Member
    • Jan 2007
    • 14

    can i do this in a loop?

    Code:
    if(a.charAt(i)!= tab[0] && a.charAt(i)!= tab[1] && a.charAt(i)!= tab[2]
                         && a.charAt(i)!= tab[3] 
                         && a.charAt(i)!= tab[4]  
                         && a.charAt(i)!= tab[5]
                         && a.charAt(i)!= tab[6] 
                         && a.charAt(i)!= tab[7]  
                         && a.charAt(i)!= tab[8]
                         && a.charAt(i)!= tab[9] 
                         && a.charAt(i)!= tab[10]  
                         && a.charAt(i)!= tab[11]
                         && a.charAt(i)!= tab[12] 
                         && a.charAt(i)!= tab[13] 
                         && a.charAt(i)!= tab[14] 
                         && a.charAt(i)!= tab[15] 
                         && a.charAt(i)!= tab[16] 
                         && a.charAt(i)!= tab[17]
                         && a.charAt(i)!= tab[18] 
                         && a.charAt(i)!= tab[19] 
                         && a.charAt(i)!= tab[20]
                         && a.charAt(i)!= tab[21] 
                         && a.charAt(i)!= tab[22]
                         && a.charAt(i)!= tab[23]
                         && a.charAt(i)!= tab[24]
                         && a.charAt(i)!= tab[25])
                        b+=a.charAt(i);
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    What loop? Don't be too lazy even to describe your problem clearly.

    Comment

    • metalinc
      New Member
      • Jan 2007
      • 14

      #3
      sorry...
      i'm comparing 'a.charAt(i)' with the char in array 'tab[]'.
      if all 'tab[0-25]' is not equal 'a.charAt(i)' then b += a.charAt(i).

      i want to know whether, i compare them in a loop, so i don't need so many lines of code comparing tab[0] to tab[25]?

      sorry again....

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        Originally posted by metalinc
        sorry...
        i'm comparing 'a.charAt(i)' with the char in array 'tab[]'.
        if all 'tab[0-25]' is not equal 'a.charAt(i)' then b += a.charAt(i).

        i want to know whether, i compare them in a loop, so i don't need so many lines of code comparing tab[0] to tab[25]?

        sorry again....
        Google "Java for-loop tutorial"

        Comment

        • JosAH
          Recognized Expert MVP
          • Mar 2007
          • 11453

          #5
          Hint: just create a small method for this: if a character *does* match one of the
          characters in that array then *don't* do what you would do otherwise:

          [code=java]
          private boolean isMatch(char c, char[] a) {
          for (int i= 0; i < a.length; i++)
          if (a[i] == c) return true;
          return false;
          }
          [/code]

          kind regards,

          Jos

          Comment

          • metalinc
            New Member
            • Jan 2007
            • 14

            #6
            thanks Jos, i got it....

            Comment

            Working...