0

sorry for not posting a final post, i found a quick fix to find my answer, here if my final code, thanks for all the help, everyone!

package random;
public class random20 {
public static void main(String[] args) {
        boolean flag = false;
        boolean flag1 = false;
        boolean flag2 = false;
        boolean flag3 = false;
        int count = 1;
        double plusminus = 0;
        double top = 4;
        double bot = 1;
        double pi = 4;
        double piequals = top/bot;

        while(plusminus == 0 || plusminus == 1){
        	if (plusminus == 0){
                piequals = top /(bot+(count*2));
                pi = pi - piequals;
                plusminus = plusminus + 1;
                if (flag != true){
                    if ((int) Math.floor (pi * 100) == 314) {
                        System.out.println("\npi = 3.14?");
                        System.out.printf("This took " + count + "times \n");
                        System.out.println("-------------------------------");
                        flag = true;
                    }
                }
                else if (flag1 != true){
                    if ((int) Math.floor (pi * 1000) == 3141) {
                        System.out.println("\npi = 3.141?");
                        System.out.printf("This took " + count + "times \n");
                        System.out.println("-------------------------------");
                        flag1 = true;
                    }
                }
                else if (flag2 != true){
                    if ((int) Math.floor (pi * 10000) == 31415){
                        System.out.println("\npi = 3.1415?");
                        System.out.printf("This took " + count + "times" + "\n");
                        System.out.println("-------------------------------");
                        flag2 = true;
                    }
                }
                else if (flag3 != true){
                    if ((int) Math.floor (pi * 100000) == 314159){
                        System.out.println("\npi = 3.14159?");
                        System.out.printf("This took " + count + "times" +  "\n");
                        System.out.println("-------------------------------");
                        flag3 = true;
                        }
                }
                else {
                    break;
                }
            }
            else if (plusminus == 1){
                piequals = top/(bot+(count*2));
                pi = pi + piequals;
                plusminus = plusminus - 1;

                if (flag != true){
                    if ((int) Math.floor (pi * 100) == 314) {
                        System.out.println("\npi = 3.14?");
                        System.out.printf("This took " + count + "times \n");
                        System.out.println("-------------------------------");
                        flag = true;
                    }
                }
                else if (flag1 != true){
                    if ((int) Math.floor (pi * 1000) == 3141) {
                        System.out.println("\npi = 3.141?");
                        System.out.printf("This took " + count + "times \n");
                        System.out.println("-------------------------------");
                        flag1 = true;
                    }
                }
                else if (flag2 != true){
                    if ((int) Math.floor (pi * 10000) == 31415){
                        System.out.println("\npi = 3.1415?");
                        System.out.printf("This took " + count + "times" + "\n");
                        System.out.println("-------------------------------");
                        flag2 = true;
                    }
                }
                else if (flag3 != true){
                    if ((int) Math.floor (pi * 100000) == 314159){
                        System.out.println("\npi = 3.14159?");
                        System.out.printf("This took " + count + "times" +  "\n");
                        System.out.println("-------------------------------");
                        flag3 = true;
                        }
                }
                else {
                    break;
                }
            }
                count++;
        }
    }
}
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.