IN JAVA Create a program that uses a while loop to display the…
Question Answered step-by-step IN JAVA Create a program that uses a while loop to display the… IN JAVA Create a program that uses a while loop to display the following math operations both in the smaller to larger order and then the larger to smaller order with the denominator being 3 through 99. Ensure your application displays the mathematical results. 1/3 + 1/5 + 1/7 + ··· + 1/95 + 1/97 + 1/991/99 + 1/97 + 1/95 + ··· + 1/7 + 1/5 + 1/3 My program works but I was just informed that instead of writing it how it is written in the question we are to actually write the fractions divided. Ex: .33 + .2 + .14 and so on displayed instead of having 1/3 + 1/5 + 1/7 displayed from smallest to largest and largest to smallest. Can someone help me fix this in my code? public class App { // function to print math operations static void printSeriesandSum() { // initialize variables to 0 double sumOfSeries = 0.0; double sumOfSeries1 = 0.0; // while loop to display smaller to larger operations // declare variable to run loop System.out.println(“nnSeries from smaller to larger: n”); int i = 2; // run loop until 99 while(i<=50) { // generate term and calculate sum sumOfSeries += 1.0/(2 * i - 1); // print series System.out.print("1/"+(2 * i - 1)); if(i<50) System.out.print(" + "); // increment loop counter i++; } // print the final sum of series System.out.println("nSum of series = " +sumOfSeries); System.out.println("nnSeries from larger to smaller: n"); // while loop to display larger to smaller operations // declare variable to run loop int j = 50; // run while loop until first number while(j>=2) { // generate term and calculate sum sumOfSeries1 += 1.0/(2 * j – 1); // print series System.out.print(“1/”+(2 * j – 1)); if(j>2) System.out.print(” + “); // decrement loop counter j–; } // print the final sum of series System.out.println(“nSum of series = ” +sumOfSeries1); } // main function public static void main (String[] args) { // call the function printSeriesandSum(); }} Computer Science Engineering & Technology Java Programming COMPUTERS CSD200 Share QuestionEmailCopy link Comments (0)


