• Post Reply Bookmark Topic Watch Topic
  • New Topic

Letters of a string that occur from the second half of the alphabet  RSS feed

 
Trish Huynh
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ugh. I'm back at it again...

I'm totally stuck on the last problem on my study guide and I have no idea where to start. I know for sure that there's a for loop involved. Any help is appreciated. So far we have only learned up to Strings, scanners, for loops and if/else statements.

Write a method named secondHalfLetters that accepts a string as its parameter and returns an integer representing how many of letters in the string come from the second half of the alphabet (that is, have values of 'n' through 'z' inclusive). Compare case-insensitively, such that uppercase values of 'N' through 'Z' also count. For example, the call secondHalfLetters("ruminates") should return 5 because the 'r', 'u', 'n', 't', and 's' come from the second half of the alphabet. You may assume that every character in the string is a letter.
 
Campbell Ritchie
Marshal
Posts: 56598
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There might be another sort of loop.

What are chars? Most beginners have been given the wrong impression about them.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
start small. do many, many, many compile/test/debug cycles. do five times more than you think you should.

The first thing I would do is write a method called secondHalfLetters that doesn't take anything or return anything. Just have it print "i'm in the method secondHalfLetters ". once you have that working, try changing it to return an int - and make that int ALWAYS 5. test that. prove you get back the 5.

Then try changing it to pass in a string and print that string out - leaving the return value of 5.

test, debug etc.

Then see if you can print each character from the string you pass in (still returning 5).

that's how you code. you build it up in teeny, tiny pieces, making sure everything works at every step.
 
Scott Winterbourne
Ranch Hand
Posts: 116
2
Eclipse IDE Java PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's a hint for where you might want to start looking.

Strings can be broken up into individual characters (char). Each char has a numerical representation that you can get using one of Character class methods. Then maybe check to see if that numeric value is greater than or equal to a certain number, and that will tell you if it is from the latter half of the alphabet.

Hope that helps point you in the right direction.

Really and truely follow the advice that Fred gave above. Breaking up the development into many many small compile/test/debug cycles will keep you from getting way down the road only to find that something or many things in the application are not working properly and having to spend a ton of time trying to track down the bug. It will also help you learn exactly how everthing works.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!