如题:
编写一个程序,表格化输出x的正弦值。其中,x是间距相等且把0-兀的区间17等分的值(输出18个正弦值)。提示:可以使用Math.PI和Math.sin()方法。输出结果如下,分两列输出。
import java.math.RoundingMode;
import java.text.DecimalFormat;
/**
* @author by Moye
* @date 2020/3/26.
*/
public class PI {
public static void main(String[] args) {
DecimalFormat formater = new DecimalFormat("0.000");
double pi = Math.PI;
for (int i = 0; i < 18; i++) {
if (i % 2 == 1) {
System.out.print(formater.format(Math.sin(pi * (i + 1) / 18)));
System.out.print("\t");
} else {
System.out.println();
System.out.print(formater.format(Math.sin(pi * (i + 1) / 18)));
System.out.print("\t");
}
}
}
}