• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Last Questiion for today I hope char.length

 
Ranch Hand
Posts: 285
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
public static boolean is_special(char value)

{
char[] special_chars = {'#', '$', '%', '&', '*', '.', ','};

for (int i = 0; i!=special_chars.length(); i++)
{
if (value==special_chars[i])
return true;
}
return false;
}

I dont think it likes this line
special_chars.length()
 
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Anthony,
You are correct. The method length is not defined for arrays. It is defined for String however:
String s = "Yesterday";
int i = s.length(); // Equals 9.
You want the field length that is defined for arrays:
String[] as = {"Yesterday", "Today", "Tommorrow"};
int i = as.length; // Equals 3.
Regards,
Manfred.
 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
length is a property of Arrays, so you could use spec_char.length
 
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, length is not a method but a property of arrays so you just need to drop the '()'.
reply
    Bookmark Topic Watch Topic
  • New Topic