plzz help me out in this java program!!!!

write a program in java to calculate the number of times the word "object" is present in the sentence :- object & class are the two basic principles of object oriented programming.


The answer is 2.

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

2 solutions

Brock Brown
Jan 7, 2015

Much simpler in Python:

1
2
sentence = "object & class are the two basic principles of object oriented programming"
print sentence.count('object')

thank you........but i just have to use java only as per my school syllabus

Dharini Chaudhary - 6 years, 5 months ago

Log in to reply

Please post such questions as notes or ask them in a programming Q&A website. Anyways here is the solution -

String line = "object & class are the two basic principles of object oriented programming.".toLowerCase();

System.out.println(line.length() - line.replace("object", "").length());

Aryan Gaikwad - 6 years, 3 months ago
Parveen Soni
Jan 6, 2015

thanx......... :)

Dharini Chaudhary - 6 years, 5 months ago

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...