Discuss / Java / 引入一个临时变量

引入一个临时变量

Topic source
public class Main {

	public static void main(String[] args) {
		double pi = 0;
		int tmp = 1;
		for (int i = 1; i < 100000; i += 2) {
			pi = pi + tmp*4*1/(double)i;
			tmp = tmp * (-1);
		}
		System.out.println(pi);
	}

}

  • 1

Reply