even and odd

Reply

Join Date: Oct 2009
Posts: 4
Reputation: ki72 is an unknown quantity at this point 
Solved Threads: 0
ki72 ki72 is offline Offline
Newbie Poster

even and odd

 
0
  #1
Oct 22nd, 2009
if and if-else statement:
you will have to write a program that reads a 4-digit positive integer from the user and prints out the following information on the screen:
1. Whether the positive integer is an odd or even number
2. (display) The odd digits of the integer
3. (display) The even digits of the integer
4. Whether the number reads the same forwards and backwards (e.g., 4004, 4444, etc.)
5. Whether all four digits are the same (e.g., 8888)
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 1,563
Reputation: BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all 
Solved Threads: 196
BestJewSinceJC BestJewSinceJC is offline Offline
Posting Virtuoso
 
1
  #2
Oct 22nd, 2009
Originally Posted by ki72 View Post
you will have to write a program that reads a 4-digit positive integer from the user and prints out the following information on the screen:
Re-read your project assignment. Pay particular attention to the part that I bolded.
Out.
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 609
Reputation: freesoft_2000 is an unknown quantity at this point 
Solved Threads: 7
freesoft_2000 freesoft_2000 is offline Offline
Practically a Master Poster
 
1
  #3
Oct 22nd, 2009
1st Part

  1. public void posneg (String str1)
  2. {
  3. Convert the string to int
  4. Divide it by 2,
  5. if there is a remainder, its odd
  6. if not even
  7. }

second part

  1. public void numposneg (String str2)
  2. {
  3. see the String api, there is an api that converts
  4. the string to a char array
  5.  
  6. call posneg
  7. }

third part

  1. public void numposneg (String str2)
  2. {
  3. see the String api, there is an api that converts
  4. the string to a char array
  5.  
  6. compare the first and last index only
  7. }

last part

well you should be able to compare if
both number are equal

What would you kids do without richard west doing your homework

Richard West
Last edited by freesoft_2000; Oct 22nd, 2009 at 2:08 pm.
Microsoft uses "One World, One Web, One Program" as a slogan.
Doesn’t that sound like "Ein Volk, Ein Reich, Ein Führer" to you, too?
— Eric S. Raymond

Tell me what type of software do you like and what would you pay for it

http://www.daniweb.com/techtalkforums/thread19660.html
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC