Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: School Help

  1. #1
    Junior Member
    Join Date
    Mar 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default School Help

    import java.util.Scanner;
    	public class Assign7_Wood {
    		public static void main (String[] args) {
    			Scanner myScanner = new Scanner(System.in);
    			double sum
    			double PI
     
    			for ( i=2; i <= 1000 ; i = i +2 ){
    			     sum = sum - something +  something
    			     PI = 4.0 * ( 1.0 + sum )
    			 }
     
    			 System.out.println("When i is 800  PI is:  ")
    			 System.out.println("When i is 900  PI is:  ")
    			 System.out.println("When i is 1000 PI is:  ")
     
     
     
     
     
     
     
     
     
    		}
    	}
    Assignment 7

    Mathematicians define the constant PI to be

    PI = 4 *( 1 - 1/(2*2-1) + 1/(2*2+1) - 1/(2*4-1) + 1/(2*4+1) - 1/(2*6-1) + 1/(2*6+1)- . . . .format . . . . . - 1/(2*i-1) + 1/(2*i+1) )

    Note that i starts at 2 and is incremented by 2. The higher the i, the more precise PI will be. Also note that the higher the value of i, the smaller the value of PI.



    Write a program that displays the value of PI for i = 800, 900 and 1000. Output should be something like this :

    when i is 800 PI is xxxx

    when i is 900 PI is xxxx

    when i is 1000 PI is xxxx
    I expect your program to look something like this :
         double sum 
         double PI
          for ( i=2; i <= 1000 ; i = i +2 )
         {
                 sum = sum - something +  something 
                 PI = 4.0 * ( 1.0 + sum )
     
          }

    Once you have this working, enhance the program, add another section. The next section of the program should determine the value of i needed to achieve a value of PI that is equal to or slightly smaller than 3.1419. The program should output the following message :

    value of i to give PI equal or smaller than 3.1419 is xxxxxx

    Name of program should be Assign7_{your last name} .

    Programs should have comments and output pasted at the bottom in the same style and manner of previous assignments.

    Above is what i have so far and am not doint so well. I have no idea what he expects in the something part in the variable sum
    Last edited by helloworld922; March 24th, 2010 at 10:42 PM.


  2. #2
    Junior Member
    Join Date
    Mar 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: School Help

    Okay Figured out the first part of the Program now working on the next section
    here is the correct if anybody else has this teacher later on here is the correct program
    import java.util.Scanner;
    	public class Assign7_Wood {
    		public static void main (String[] args) {
    			Scanner myScanner = new Scanner(System.in);
    			double sum =0;
    			double PI = 0;
    			double PIa = 0;
    			double PIb = 0;
    			double PIc = 0;
    			double i = 2;
     
    			for ( i=2; i <= 1000 ; i = i +2 ){
    			     sum = sum - 1/(2*i-1) +  1/(2*i+1);
    			     PI = 4.0 * ( 1.0 + sum );
     
    			     if(i == 800){
    					 PIa = PI;
    			     }
                     if(i == 900){
    					 PIb = PI;
    				 }
    				 if(i == 1000){
    					 PIc = PI;
    			 }}
     
    System.out.println("When i is 800  PI is:  " +PIa);
    System.out.println("When i is 900  PI is:  " +PIb);
    System.out.println("When i is 1000 PI is:  " +PIc);
    Last edited by helloworld922; March 24th, 2010 at 10:44 PM.

Similar Threads

  1. Java program for to implement supermarket menu
    By 5723 in forum AWT / Java Swing
    Replies: 1
    Last Post: April 14th, 2009, 04:14 AM
  2. How to use for loop for movement of points in a picture display?
    By Dman in forum What's Wrong With My Code?
    Replies: 3
    Last Post: April 8th, 2009, 10:19 AM