Excellent! Many thanks for that.
James
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
gabec94 0 Junior Poster in Training
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++;
}
}
}
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.