Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

JAVA Hey guys, I need this error in output fixed. My code is producing this output below. 1000 -2 -1 500 Your output ends with

 
JAVA
Hey guys, I need this error in output fixed.
My code is producing this output below.
1000 -2 -1 500 Your output ends with RESULTS At term 2: Pi = 2.666666667 At term 4: Pi = 2.895238095 At term 6: Pi = 2.976046176 At term 8: Pi = 3.017071817 At term 10: Pi = 3.041839619 At term 12: Pi = 3.058402766 At term 14: Pi = 3.070254618 At term 16: Pi = 3.079153394 At term 18: Pi = 3.086079801 At term 20: Pi = 3.091623807 At term 22: Pi = 3.096161526 At term 24: Pi = 3.099944032 At term 26: Pi = 3.103145313 At term 28: Pi = 3.105889738 At term 30: Pi = 3.108268567 At term 32: Pi = 3.110350274 At term 34: Pi = 3.112187243 At term 36: Pi = 3.113820229 At term 38: Pi = 3.115281416 At term 40: Pi = 3.116596557 At term 42: Pi = 3.117786502 At term 44: Pi = 3.118868314 At term 46: Pi = 3.119856090 At term 48: Pi = 3.120761580 At term 50: Pi = 3.121594653 At term 52: Pi = 3.122363662 At term 54: Pi = 3.123075722 At term 56: Pi = 3.123736934 At term 58: Pi = 3.124352555 At term 60: Pi = 3.124927144 At term 62: Pi = 3.125464670 At term 64: Pi = 3.125968607 At term 66: Pi = 3.126442008 At term 68: Pi = 3.126887566 At term 70: Pi = 3.127307668 At term 72: Pi = 3.127704434 At term 74: Pi = 3.128079757 At term 76: Pi = 3.128435328 At term 78: Pi = 3.128772667 At term 80: Pi = 3.129093142 At term 82: Pi = 3.129397985 At term 84: Pi = 3.129688313 At term 86: Pi = 3.129965140 At term 88: Pi = 3.130229384 At term 90: Pi = 3.130481885 At term 92: Pi = 3.130723409 At term 94: Pi = 3.130954657 At term 96: Pi = 3.131176269 At term 98: Pi = 3.131388838 At term 100: Pi = 3.131592904 At term 102: Pi = 3.131788968 At term 104: Pi = 3.131977491 At term 106: Pi = 3.132158901 At term 108: Pi = 3.132333593 At term 110: Pi = 3.132501932 At term 112: Pi = 3.132664260 At term 114: Pi = 3.132820892 At term 116: Pi = 3.132972124 At term 118: Pi = 3.133118229 At term 120: Pi = 3.133259465 At term 122: Pi = 3.133396070 At term 124: Pi = 3.133528269 At term 126: Pi = 3.133656271 At term 128: Pi = 3.133780273 At term 130: Pi = 3.133900460 At term 132: Pi = 3.134017005 At term 134: Pi = 3.134130071 At term 136: Pi = 3.134239812 At term 138: Pi = 3.134346372 At term 140: Pi = 3.134449888 At term 142: Pi = 3.134550487 At term 144: Pi = 3.134648293 At term 146: Pi = 3.134743419 At term 148: Pi = 3.134835974 At term 150: Pi = 3.134926061 At term 152: Pi = 3.135013777 At term 154: Pi = 3.135099216 At term 156: Pi = 3.135182463 At term 158: Pi = 3.135263603 At term 160: Pi = 3.135342715 At term 162: Pi = 3.135419873 At term 164: Pi = 3.135495149 At term 166: Pi = 3.135568612 At term 168: Pi = 3.135640325 At term 170: Pi = 3.135710352 At term 172: Pi = 3.135778749 At term 174: Pi = 3.135845575 At term 176: Pi = 3.135910881 At term 178: Pi = 3.135974720 At term 180: Pi = 3.136037141 At term 182: Pi = 3.136098190 At term 184: Pi = 3.136157911 At term 186: Pi = 3.136216348 At term 188: Pi = 3.136273542 At term 190: Pi = 3.136329532 At term 192: Pi = 3.136384356 At term 194: Pi = 3.136438049 At term 196: Pi = 3.136490646 At term 198: Pi = 3.136542181 At term 200: Pi = 3.136592685 At term 202: Pi = 3.136642189 At term 204: Pi = 3.136690722 At term 206: Pi = 3.136738313 At term 208: Pi = 3.136784989 At term 210: Pi = 3.136830776 At term 212: Pi = 3.136875699 At term 214: Pi = 3.136919782 At term 216: Pi = 3.136963049 At term 218: Pi = 3.137005522 At term 220: Pi = 3.137047223 At term 222: Pi = 3.137088172 At term 224: Pi = 3.137128390 At term 226: Pi = 3.137167896 At term 228: Pi = 3.137206710 At term 230: Pi = 3.137244848 At term 232: Pi = 3.137282329 At term 234: Pi = 3.137319169 At term 236: Pi = 3.137355384 At term 238: Pi = 3.137390991 At term 240: Pi = 3.137426005 At term 242: Pi = 3.137460440 At term 244: Pi = 3.137494310 At term 246: Pi = 3.137527630 At term 248: Pi = 3.137560412 At term 250: Pi = 3.137592670 At term 252: Pi = 3.137624415 At term 254: Pi = 3.137655661 At term 256: Pi = 3.137686418 At term 258: Pi = 3.137716699 At term 260: Pi = 3.137746514 At term 262: Pi = 3.137775874 At term 264: Pi = 3.137804788 At term 266: Pi = 3.137833268 At term 268: Pi = 3.137861323 At term 270: Pi = 3.137888963 At term 272: Pi = 3.137916195 At term 274: Pi = 3.137943031 At term 276: Pi = 3.137969477 At term 278: Pi = 3.137995543 At term 280: Pi = 3.138021236 At term 282: Pi = 3.138046565 At term 284: Pi = 3.138071538 At term 286: Pi = 3.138096161 At term 288: Pi = 3.138120442 At term 290: Pi = 3.138144388 At term 292: Pi = 3.138168006 At term 294: Pi = 3.138191303 At term 296: Pi = 3.138214285 At term 298: Pi = 3.138236958 At term 300: Pi = 3.138259330 At term 302: Pi = 3.138281404 At term 304: Pi = 3.138303189 At term 306: Pi = 3.138324688 At term 308: Pi = 3.138345909 At term 310: Pi = 3.138366856 At term 312: Pi = 3.138387534 At term 314: Pi = 3.138407948 At term 316: Pi = 3.138428105 At term 318: Pi = 3.138448007 At term 320: Pi = 3.138467661 At term 322: Pi = 3.138487071 At term 324: Pi = 3.138506241 At term 326: Pi = 3.138525176 At term 328: Pi = 3.138543880 At term 330: Pi = 3.138562358 At term 332: Pi = 3.138580612 At term 334: Pi = 3.138598648 At term 336: Pi = 3.138616470 At term 338: Pi = 3.138634080 At term 340: Pi = 3.138651483 At term 342: Pi = 3.138668683 At term 344: Pi = 3.138685683 At term 346: Pi = 3.138702486 At term 348: Pi = 3.138719096 At term 350: Pi = 3.138735517 At term 352: Pi = 3.138751750 At term 354: Pi = 3.138767800 At term 356: Pi = 3.138783670 At term 358: Pi = 3.138799363 At term 360: Pi = 3.138814881 At term 362: Pi = 3.138830228 At term 364: Pi = 3.138845406 At term 366: Pi = 3.138860418 At term 368: Pi = 3.138875267 At term 370: Pi = 3.138889956 At term 372: Pi = 3.138904486 At term 374: Pi = 3.138918862 At term 376: Pi = 3.138933084 At term 378: Pi = 3.138947156 At term 380: Pi = 3.138961079 At term 382: Pi = 3.138974857 At term 384: Pi = 3.138988491 At term 386: Pi = 3.139001984 At term 388: Pi = 3.139015338 At term 390: Pi = 3.139028555 At term 392: Pi = 3.139041637 At term 394: Pi = 3.139054587 At term 396: Pi = 3.139067405 At term 398: Pi = 3.139080095 At term 400: Pi = 3.139092657 At term 402: Pi = 3.139105095 At term 404: Pi = 3.139117410 At term 406: Pi = 3.139129603 At term 408: Pi = 3.139141677 At term 410: Pi = 3.139153633 At term 412: Pi = 3.139165473 At term 414: Pi = 3.139177198 At term 416: Pi = 3.139188811 At term 418: Pi = 3.139200313 At term 420: Pi = 3.139211705 At term 422: Pi = 3.139222989 At term 424: Pi = 3.139234166 At term 426: Pi = 3.139245239 At term 428: Pi = 3.139256208 At term 430: Pi = 3.139267075 At term 432: Pi = 3.139277842 At term 434: Pi = 3.139288509 At term 436: Pi = 3.139299079 At term 438: Pi = 3.139309552 At term 440: Pi = 3.139319929 At term 442: Pi = 3.139330213 At term 444: Pi = 3.139340404 At term 446: Pi = 3.139350504 At term 448: Pi = 3.139360514 At term 450: Pi = 3.139370434 At term 452: Pi = 3.139380267 At term 454: Pi = 3.139390013 At term 456: Pi = 3.139399674 At term 458: Pi = 3.139409250 At term 460: Pi = 3.139418743 At term 462: Pi = 3.139428154 At term 464: Pi = 3.139437484 At term 466: Pi = 3.139446733 At term 468: Pi = 3.139455904 At term 470: Pi = 3.139464996 At term 472: Pi = 3.139474012 At term 474: Pi = 3.139482951 At term 476: Pi = 3.139491816 At term 478: Pi = 3.139500606 At term 480: Pi = 3.139509323 At term 482: Pi = 3.139517967 At term 484: Pi = 3.139526540 At term 486: Pi = 3.139535043 At term 488: Pi = 3.139543475 At term 490: Pi = 3.139551839 At term 492: Pi = 3.139560135 At term 494: Pi = 3.139568364 At term 496: Pi = 3.139576527 At term 498: Pi = 3.139584623 At term 500: Pi = 3.139592656 At term 502: Pi = 3.139600624 At term 504: Pi = 3.139608529 At term 506: Pi = 3.139616371 At term 508: Pi = 3.139624152 At term 510: Pi = 3.139631871 At term 512: Pi = 3.139639530 At term 514: Pi = 3.139647130 At term 516: Pi = 3.139654671 At term 518: Pi = 3.139662153 At term 520: Pi = 3.139669578 At term 522: Pi = 3.139676947 At term 524: Pi = 3.139684258 At term 526: Pi = 3.139691515 At term 528: Pi = 3.139698716 At term 530: Pi = 3.139705863 At term 532: Pi = 3.139712956 At term 534: Pi = 3.139719996 At term 536: Pi = 3.139726984 At term 538: Pi = 3.139733919 At term 540: Pi = 3.139740803 At term 542: Pi = 3.139747637 At term 544: Pi = 3.139754420 At term 546: Pi = 3.139761153 At term 548: Pi = 3.139767838 At term 550: Pi = 3.139774473 At term 552: Pi = 3.139781061 At term 554: Pi = 3.139787601 At term 556: Pi = 3.139794094 At term 558: Pi = 3.139800540 At term 560: Pi = 3.139806941 At term 562: Pi = 3.139813296 At term 564: Pi = 3.139819605 At term 566: Pi = 3.139825871 At term 568: Pi = 3.139832092 At term 570: Pi = 3.139838269 At term 572: Pi = 3.139844403 At term 574: Pi = 3.139850495 At term 576: Pi = 3.139856544 At term 578: Pi = 3.139862551 At term 580: Pi = 3.139868517 At term 582: Pi = 3.139874442 At term 584: Pi = 3.139880326 At term 586: Pi = 3.139886170 At term 588: Pi = 3.139891975 At term 590: Pi = 3.139897740 At term 592: Pi = 3.139903466 At term 594: Pi = 3.139909153 At term 596: Pi = 3.139914802 At term 598: Pi = 3.139920414 At term 600: Pi = 3.139925988 At term 602: Pi = 3.139931525 At term 604: Pi = 3.139937026 At term 606: Pi = 3.139942490 At term 608: Pi = 3.139947918 At term 610: Pi = 3.139953310 At term 612: Pi = 3.139958668 At term 614: Pi = 3.139963990 At term 616: Pi = 3.139969278 At term 618: Pi = 3.139974532 At term 620: Pi = 3.139979751 At term 622: Pi = 3.139984938 At term 624: Pi = 3.139990091 At term 626: Pi = 3.139995211 At term 628: Pi = 3.140000298 At term 630: Pi = 3.140005353 At term 632: Pi = 3.140010376 At term 634: Pi = 3.140015368 At term 636: Pi = 3.140020328 At term 638: Pi = 3.140025256 At term 640: Pi = 3.140030155 At term 642: Pi = 3.140035022 At term 644: Pi = 3.140039859 At term 646: Pi = 3.140044667 At term 648: Pi = 3.140049445 At term 650: Pi = 3.140054193 At term 652: Pi = 3.140058912 At term 654: Pi = 3.140063602 At term 656: Pi = 3.140068264 At term 658: Pi = 3.140072898 At term 660: Pi = 3.140077503 At term 662: Pi = 3.140082080 At term 664: Pi = 3.140086630 At term 666: Pi = 3.140091153 At term 668: Pi = 3.140095648 At term 670: Pi = 3.140100117 At term 672: Pi = 3.140104559 At term 674: Pi = 3.140108975 At term 676: Pi = 3.140113364 At term 678: Pi = 3.140117728 At term 680: Pi = 3.140122066 At term 682: Pi = 3.140126379 At term 684: Pi = 3.140130666 At term 686: Pi = 3.140134928 At term 688: Pi = 3.140139166 At term 690: Pi = 3.140143379 At term 692: Pi = 3.140147568 At term 694: Pi = 3.140151732 At term 696: Pi = 3.140155873 At term 698: Pi = 3.140159990 At term 700: Pi = 3.140164083 At term 702: Pi = 3.140168153 At term 704: Pi = 3.140172200 At term 706: Pi = 3.140176224 At term 708: Pi = 3.140180225 At term 710: Pi = 3.140184204 At term 712: Pi = 3.140188160 At term 714: Pi = 3.140192094 At term 716: Pi = 3.140196006 At term 718: Pi = 3.140199897 At term 720: Pi = 3.140203765 At term 722: Pi = 3.140207613 At term 724: Pi = 3.140211439 At term 726: Pi = 3.140215244 At term 728: Pi = 3.140219028 At term 730: Pi = 3.140222791 At term 732: Pi = 3.140226534 At term 734: Pi = 3.140230256 At term 736: Pi = 3.140233959 At term 738: Pi = 3.140237641 At term 740: Pi = 3.140241303 At term 742: Pi = 3.140244945 At term 744: Pi = 3.140248568 At term 746: Pi = 3.140252172 At term 748: Pi = 3.140255756 At term 750: Pi = 3.140259321 At term 752: Pi = 3.140262867 At term 754: Pi = 3.140266394 At term 756: Pi = 3.140269903 At term 758: Pi = 3.140273393 At term 760: Pi = 3.140276865 At term 762: Pi = 3.140280318 At term 764: Pi = 3.140283754 At term 766: Pi = 3.140287171 At term 768: Pi = 3.140290571 At term 770: Pi = 3.140293953 At term 772: Pi = 3.140297317 At term 774: Pi = 3.140300664 At term 776: Pi = 3.140303994 At term 778: Pi = 3.140307307 At term 780: Pi = 3.140310603 At term 782: Pi = 3.140313882 At term 784: Pi = 3.140317144 At term 786: Pi = 3.140320389 At term 788: Pi = 3.140323619 At term 790: Pi = 3.140326831 At term 792: Pi = 3.140330028 At term 794: Pi = 3.140333208 At term 796: Pi = 3.140336373 At term 798: Pi = 3.140339521 At term 800: Pi = 3.140342654 At term 802: Pi = 3.140345771 At term 804: Pi = 3.140348873 At term 806: Pi = 3.140351959 At term 808: Pi = 3.140355030 At term 810: Pi = 3.140358086 At term 812: Pi = 3.140361127 At term 814: Pi = 3.140364153 At term 816: Pi = 3.140367164 At term 818: Pi = 3.140370160 At term 820: Pi = 3.140373142 At term 822: Pi = 3.140376109 At term 824: Pi = 3.140379062 At term 826: Pi = 3.140382000 At term 828: Pi = 3.140384925 At term 830: Pi = 3.140387835 At term 832: Pi = 3.140390731 At term 834: Pi = 3.140393613 At term 836: Pi = 3.140396482 At term 838: Pi = 3.140399337 At term 840: Pi = 3.140402178 At term 842: Pi = 3.140405006 At term 844: Pi = 3.140407820 At term 846: Pi = 3.140410621 At term 848: Pi = 3.140413409 At term 850: Pi = 3.140416183 At term 852: Pi = 3.140418945 At term 854: Pi = 3.140421694 At term 856: Pi = 3.140424430 At term 858: Pi = 3.140427153 At term 860: Pi = 3.140429863 At term 862: Pi = 3.140432561 At term 864: Pi = 3.140435247 At term 866: Pi = 3.140437920 At term 868: Pi = 3.140440580 At term 870: Pi = 3.140443229 At term 872: Pi = 3.140445865 At term 874: Pi = 3.140448489 At term 876: Pi = 3.140451101 At term 878: Pi = 3.140453702 At term 880: Pi = 3.140456290 At term 882: Pi = 3.140458867 At term 884: Pi = 3.140461432 At term 886: Pi = 3.140463986 At term 888: Pi = 3.140466528 At term 890: Pi = 3.140469058 At term 892: Pi = 3.140471578 At term 894: Pi = 3.140474086 At term 896: Pi = 3.140476583 At term 898: Pi = 3.140479068 At term 900: Pi = 3.140481543 At term 902: Pi = 3.140484006 At term 904: Pi = 3.140486459 At term 906: Pi = 3.140488901 At term 908: Pi = 3.140491332 At term 910: Pi = 3.140493753 At term 912: Pi = 3.140496163 At term 914: Pi = 3.140498562 At term 916: Pi = 3.140500951 At term 918: Pi = 3.140503329 At term 920: Pi = 3.140505697 At term 922: Pi = 3.140508055 At term 924: Pi = 3.140510403 At term 926: Pi = 3.140512740 At term 928: Pi = 3.140515068 At term 930: Pi = 3.140517385 At term 932: Pi = 3.140519693 At term 934: Pi = 3.140521990 At term 936: Pi = 3.140524278 At term 938: Pi = 3.140526556 At term 940: Pi = 3.140528824 At term 942: Pi = 3.140531083 At term 944: Pi = 3.140533332 At term 946: Pi = 3.140535571 At term 948: Pi = 3.140537802 At term 950: Pi = 3.140540022 At term 952: Pi = 3.140542234 At term 954: Pi = 3.140544436 At term 956: Pi = 3.140546629 At term 958: Pi = 3.140548813 At term 960: Pi = 3.140550987 At term 962: Pi = 3.140553153 At term 964: Pi = 3.140555309 At term 966: Pi = 3.140557457 At term 968: Pi = 3.140559596 At term 970: Pi = 3.140561726 At term 972: Pi = 3.140563847 At term 974: Pi = 3.140565960 At term 976: Pi = 3.140568064 At term 978: Pi = 3.140570159 At term 980: Pi = 3.140572246 At term 982: Pi = 3.140574324 At term 984: Pi = 3.140576394 At term 986: Pi = 3.140578455 At term 988: Pi = 3.140580508 At term 990: Pi = 3.140582553 At term 992: Pi = 3.140584589 At term 994: Pi = 3.140586618 At term 996: Pi = 3.140588638 At term 998: Pi = 3.140590650 At term 1000: Pi = 3.140592654 Final Pi at term 1000 = 3.140592654
I need my code to look like the output below. Same input are used as above*
RESULTS At term 500: Pi = 3.139592656 At term 1000: Pi = 3.140592654 Final Pi at term 1000 = 3.140592654
 
 
import java.util.Scanner; public class PiApproximator { public static int userInput(String prompt, Scanner scn) { System.out.println( prompt ); int value = scn.nextInt(); // Taking the user input return value; } public static void printPi(int terms, int displayCount) { double pi = 0; //intialising pi to zero int i; double den; den = 1; //intialising denominator to zero for (i = 1; i <= terms; i++) { if (i % 2 == 1) { // for adding the fraction 4/denominator pi = pi + (4 / den); if (i % displayCount == 0) { // Displaying Pi value if 'i' is multiple of displayCOunt System.out.printf( "At term " + i + ": Pi = %.9f%n", pi ); } } else if (i % 2 == 0) { // for subtracting the fraction 4/denominator pi = pi - (4 / den); if (i % displayCount == 0) { // Displaying Pi value if 'i' is multiple of displayCount System.out.printf( "At term " + i + ": Pi = %.9f%n", pi ); } } den = den + 2; // Incrementing the denomiator by 2 to get values 1,3,5,7,9.... } System.out.println(""); System.out.printf( "Final Pi at term " + (i - 1) + " = %.9f%n", pi ); } public static void main(String[] args) { System.out.println( "Program will approximate Pi" ); Scanner sc = new Scanner( System.in ); // Declaring a Scanner variable // Calling userIput function int terms = userInput( "Enter the number of terms to use: ", sc ); int displayCount = userInput( "Display Pi after every how many steps? ", sc ); System.out.println(""); System.out.println( "RESULTS" ); // Calling printPi function printPi( terms, displayCount ); } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2022 Grenoble France September 19 23 2022 Proceedings Part 4 Lnai 13716

Authors: Massih-Reza Amini ,Stephane Canu ,Asja Fischer ,Tias Guns ,Petra Kralj Novak ,Grigorios Tsoumakas

1st Edition

3031264118, 978-3031264115

More Books

Students also viewed these Databases questions

Question

Show the following: (a) E(MSE) = 2, (b) (c) E(NIST ) = 12

Answered: 1 week ago