Results 1 to 5 of 5
Thread: Homework help...
 10172008, 02:07 AM #1Member
 Join Date
 Oct 2008
 Posts
 2
 Rep Power
 0
Homework help...
Here are the original directions:
For this lab you will develop and test a Class called MathTasks with the following functionality. Include in your Lab Log sample runs on all provided test data.
1. a method called sumFor that has an integer parameter n and computes the sums of all the integers from 1 to n using a for construct. (hint: We already wrote the code in class – use your notes) Test on: 3,4,5,6,7
2. a method called sumWhile that does the same thing as sumFor, except that it is written using a while construct rather than a for construct. Test on: 3,4,5,6,7
3. a method called sumDoWhile that does the same thing as sumFor and sumWhile, except that it is written using a do_while construct rather than a for or while construct. Test on: 3,4,5,6,7
4. a method called sumIJ with two integer parameters i and j and computes the sums of all the integers from i to j using the most appropriate loop construct. Test on: (1,6),(3,4),(2,7)
5. a method called printPositiveEven that has an integer parameter n and prints all positive even numbers smaller or equal to n. Test on: 3,14,25, 32
6. a method called printAllMultiplesOfThree that has an integer parameter n and prints all positive numbers smaller or equal to n that are multiples of 3. Test on: 4,9,17,26,31
7. a method called printStars that has an integer parameter n and prints a line with n * characters. Test on: 3,4,5,6
ex: if the parameter n is 5 it prints *****
if the parameter n is 8 it prints ********
8. a method called printStarLines that has two integer parameters m and n and prints m lines. The first line has n * characters, the next one n+1, and so on. Test on: (2,5),(4,2),(5,5)
ex: if the parameter m is 4 and n is 6, then it prints:
******
*******
********
*********
9. a method called printStarLinesDecreasing that has two integer parameters m and n and prints 2*m1 lines. The first line has n * characters, the next one n+1, and so on until the mth line has n+m1, the (m+1)th line has n+m2 and so on until the last one has n * characters. Test on: (2,5),(4,2),(5,5)
ex: if the parameter m is 3 and n is 5, then it prints:
*****
******
*******
******
*****
10. a method called isPowerOfTwo that has an integer parameter n and returns true if n is a power of 2, false otherwise. Test on: 3,4,8,12,32,33,100, 256,1024,1025
I need some help with the last two. Can anyone help me out? thanks!
 Can anyone help me out?
 10172008, 03:34 AM #3Member
 Join Date
 Oct 2008
 Posts
 2
 Rep Power
 0
I got #9 to work but am still lost on 10...not even sure how to start it....not allowed to use sqrt cause it has to be an integer.

Sure you can use sqrt, and in fact it's a very good idea to use sqrt here. If you call sqrt and convert the result to an int by casting, what can you do with the result to test the question? Think on that for a bit. In fact you may want to play with the test numbers with a piece of paper and a calculator (the Windows calculator would work just fine). Sqrt the test numbers, convert to int (i.e., 2.20392 becomes 2, 8.82933 becomes 8) and see how this helps you.
 10172008, 04:24 AM #5
Similar Threads

LF: Homework help with Java
By excurssion in forum New To JavaReplies: 2Last Post: 10172008, 06:00 AM 
Need help with homework.
By JavaNewbie0000 in forum New To JavaReplies: 2Last Post: 07312008, 03:06 PM 
thread homework
By integralli in forum Threads and SynchronizationReplies: 6Last Post: 06212008, 04:34 PM 
Some input on a homework
By alcohole4life in forum New To JavaReplies: 1Last Post: 05232008, 04:18 PM 
Problem using thread +rmi in my homework
By IbrahimAbbas in forum Threads and SynchronizationReplies: 10Last Post: 04142008, 09:24 PM
Bookmarks