Here is the problem statement:
Write a JAVA program using while loops to calculate and display the total of the following series:
1/30 + 2/29 + 3/28 + ... + 30/1
Here is what I have so far:
double sum=0;
int num=1;
while(num<=30)
{//begin of outer while loop
int den=30;
while(den>=1)
{//begin of inner while loop
sum+=(double)(num/den);
den--;
}//end of inner while loop
num++;
}//end of outer while loop
System.out.println("The sum is "+sum);
With this code, the output I am getting is:
run:
The sum is 1492.0
BUILD SUCCESSFUL (total time: 0 seconds)
The output is supposed to be: 93.84460106
Any help would be appreciated. Please keep in mind that I am a beginner.
Thank You!
My apologies, disregard. I meant to post this in JAVA.
Pay no attention to that bottom line, I accidentally posted this first in the VB.net forum, and just copied and pasted the original in here.

New Topic/Question
Reply




MultiQuote






|