• 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

Why does count not reflect # of tokens?

 
Ranch Hand
Posts: 144
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
class Volatile {
public static void main(String [] args) {

String s = "x1234 y56 z7 a";
String [] sa = s.split("\\d");
int count = 0;
for( String x : sa)
count++;
System.out.println("total: " + count);
}
}

What's result?

A) total: 7
B) total: 8
C) Compile error because "volatile" is a keyword

Why is answer B? Why does count not reflect # of tokens?

[ May 30, 2006: Message edited by: Firas Zureikat ]
[ May 30, 2006: Message edited by: Firas Zureikat ]
 
Ranch Hand
Posts: 809
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Why is answer B? Why does count not reflect # of tokens?



If its not typo mistake i.e. class name is volatile (v small), then correct answer will be C.

Program will not compile.

Regards

Naseem
 
Ranch Hand
Posts: 2023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
x|1|2|3|4 y|5|6 z|7 a|
that is
x|||| y|| z| a
 
Naseem Khan
Ranch Hand
Posts: 809
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When digits r used as a delimiter, continguous digits which are connected without a break result in a empty token.



Naseem
 
Firas Zuriekat
Ranch Hand
Posts: 144
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, I got it..Thanks.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic