New course! Every coder should learn Generative AI!
Try a free lesson+ 3
Sankalp๐จโ๐ป๐จโ๐ป
I will give you a tip:
Take input as a String using nextLine(). Use split(" ") method which returns a String array.
E.g. "Hello World"
-> [Hello, World]
Then it should be much easier.
+ 2
Jayakrishna punctuation does not count.
+ 2
Denise Roรberg ok. I understood that..
In 1, reply, When I posting 1 or 2 words I missed to mention, after posting I edited that.. You may read it before that...
OK. He just missing char count only.. Let us see, can he do it...
+ 2
Sankalp๐จโ๐ป๐จโ๐ป
Math.ceil () + count only letters = solution.
Edit: You can believe us. We have already solved this challenge. ;)
+ 2
Sankalp๐จโ๐ป๐จโ๐ป
I am a bot confused about
input -> XX:XX XX
Maybe you confused the challenges. Looks like military time.
But concrats that you solved it.
+ 1
why you are adding space by n=" " +n.
And use ceil function.
There mentioned to round up...
+ 1
Sankalp๐จโ๐ป๐จโ๐ป No need to add space. If you add you will get extra word count...
And use ceil function...
+ 1
Sankalp๐จโ๐ป๐จโ๐ป
Using Math.ceil() is correct.
Read the description and look at the testcase 1.
"You have to remove all punctuation".
Testcase 1 contains "?".
That's why your code fails.
+ 1
Sankalp๐จโ๐ป๐จโ๐ป Yes. I missed that one more, with that your code by char++, the punctuation marks also counts so you need calculate only charecters ..
+ 1
Denise Roรberg see his code... He is calculating all chars other than space...
Iam also telling the same...
I already solved it at the time of challenge...
+ 1
Sankalp๐จโ๐ป๐จโ๐ป Its simple...
1. Count chars without punctuations...
2. Count words
Find avg by ceil function...
I think it's better to, i give code.. Only you missing char count...
Can you try one more time for char count..
+ 1
Jayakrishna Sankalp๐จโ๐ป๐จโ๐ป
"Takes in a string, figure out the average length of all the words and return a number representing the average length. Remove all punctuation. Round up to the nearest whole number."
Remove all punctuation!
Case 1:
Can you do that?
can 3
you 3
do 2
that 4
-> 12 / 4 = 3
3.0 rounded up = 3
Case 2:
The longest word in the dictionary is...
the 3
longest 7
word 4
in 2
the 3
dictionary 10
is 2
-> 31 / 7 = 4.43
rounded up: 5
+ 1
Sankalp๐จโ๐ป๐จโ๐ป Round gives
4.42 to 4.0
4.78 to 5.0
Simply Belove 0.5 to 0.0 and above 0.5 to 1.0
ceil results both to 5.0 i.e(4.4, 4.7)
+ 1
Sankalp๐จโ๐ป๐จโ๐ป
ceil() rounds always up.
3.0 -> 3.0
3.1 - 3.9 -> 4.0
round()
2.0 - 2.4 -> 2
2.5 - 2.9 -> 3
+ 1
Jayakrishna
I misunderstood you earlier. I thought you meant in the challenge you have to count punctuation marks. Instead, you meant that his code did it.
Yes, I noticed that.
I think we're done here. I don't know what else to mention.
+ 1
Can you try it? Or can I give solution?
+ 1
Sankalp๐จโ๐ป๐จโ๐ป
OK. I already mentioned that you missing in charecter count. Use ceil function.
Look for those...
+ 1
Sankalp๐จโ๐ป๐จโ๐ป Just focus on description, not on the test cases...
+ 1
Sankalp๐จโ๐ป๐จโ๐ป we also prefer to solve by own.. So that's why I asked to try.. try... Just reminding what you missing.. We just want to know also what is your preference...
But it seems that you are not picking the logic..
I faced that situation lot of times.. If I struck, and came back in other day to solve, it's better that to reset code and write again from the start...
So do like this..
Try.. Try.. Again.. If need help then ask...
0
ndhdkdid