double sum = 0;int flag = 1;for (int i = 1; i <= 50; i++) { sum = sum + flag * 1.0 / i; flag *= -1;}System.out.println(sum);