Go Back   PCMech Forums > Help & Discussion > Web Design / Development

Need Some Help? Type Your Keywords Here:

Reply
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Old 04-01-2007, 04:42 PM   #1
Member (8 bit)
 
baseballer10p's Avatar
 
Join Date: May 2006
Location: Illinois
Posts: 235
Angry Fire This program is driving me nuts!!!

I'm having trouble with yet another Java problem for this class I'm taking in college. I'm supposed to add 1 + 1/2 + 1/3 +...+ 1/15, and print out the result using a for, do-while, or a while statement. Ill paste what I have right now.

double i, sum3;

sum3 = 0;

for (i = 1/15; i <= 1/15; i = i + (1/14))
{
sum3 = sum3 + i;
}

System.out.println("The sum of 1 + (1/2) + (1/3) + (1/4) +...+ 1/15 = " + sum3);

I know this is wrong, but I can't even get the system to print out anything to the command console. Also, I'm not sure if I'm using the right type of statement for this particular problem. If anyone knows how to do this, please help me. This one is driving me crazy!
__________________
ASUS M4A785TD-V EVO 785G | AMD Phenom II X4 955 | 2 x 2GB G.Skill Ripjaws DDR3 1600 | AMD Radeon HD 6970 | Lite-On DVD-RW | Western Digital Caviar Black 750GB | Antec Sonata III | Corsair AX850 | Windows 7 Home Premium 64-bit

Biostar NF61S-M2 TE | AMD Athlon 64 X2 5000+ | 2 x 2GB OCZ Reaper DDR2 6400 | Radeon HD 4850 | Lite-On DVD-RW | Seagate Barracuda 120GB | Antec Sonata II | Antec EarthWatts 500W | Ubuntu 11.04 64-bit
baseballer10p is offline   Reply With Quote
Old 04-01-2007, 08:00 PM   #2
Member (9 bit)
 
Join Date: Dec 2004
Posts: 289
You could do something like this:

Code:
public class asdf
{
    public static void main(String [] args) {
        double sum = 0;

        for (int i = 1; i <= 15; i++) {
            sum += (1/(double)(i));
        }
        System.out.println(sum);
    }
}
__________________
Dell Inspiron 9300
Intel Pentium M 740
17" Wide Screen XGA+ Display
1GB PC-4200 Dual Channel DDR2
256MB NVIDA GeForce Go 6800

Apple MacBook (Black)
Intel Core 2 Duo 2.16 Ghz
13" Wide screen Display
2GB Memory
PCBrandon is offline   Reply With Quote
Old 04-01-2007, 10:14 PM   #3
Member (8 bit)
 
baseballer10p's Avatar
 
Join Date: May 2006
Location: Illinois
Posts: 235
Alright, that worked! Thanks a lot for the help.
baseballer10p is offline   Reply With Quote
Old 04-02-2007, 01:05 PM   #4
Member (10 bit)
 
Join Date: Jun 2000
Location: Dorset UK
Posts: 559
I don't know about anyone else but that went straight over my head!!! you clever people lol

Doug
DougL is offline   Reply With Quote
Reply

Bookmarks

Still Need Help? Type Your Keywords Here:


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
ITE controller?? driving me nuts... erucader Computer Hardware 4 10-02-2005 04:09 AM
Touchpad driving me NUTS!! Jaggannath Computer Hardware 19 05-31-2005 02:17 AM
Sata hd driving me nuts!!!!!!! Clamptastic Computer Hardware 13 04-20-2005 08:00 AM
WinXP error on startup driving me nuts! ReBeL Windows Legacy Support (XP and earlier) 1 01-23-2002 11:05 PM
Conect problem driving me nuts Briab Guy Windows Legacy Support (XP and earlier) 8 09-05-2001 02:43 PM


All times are GMT -5. The time now is 07:27 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
SEO by vBSEO 3.6.0 PL2