开发者社区> 问答> 正文

如何使用函数来完成下表?

关于sololearn的代码第1部分][关于sololearn的代码第2部分][弧度、正切、正弦、余弦和度数表 import java.util.Scanner; public class St_Johns_University { public static void main(String[] args) { System.out.printf("%-10s%-10s%-10s%-10s%-10s\n", "Radians", "Tangent", "Sine", "Cosine", "Degrees");

    int degrees = 60;
    double radians = Math.toRadians(degrees);
    System.out.printf("%-10d%-10.4f%-10.4f%-10.4f%-10.4f\n", radians, Math.tan(radians), Math.sin(radians), Math.cos(radians), degrees);
     degrees = 80;
     radians = Math.toRadians(degrees);
    System.out.printf("%-10d%-10.4f%-10.4f%-10.4f%-10.4f\n", radians, Math.tan(radians), Math.sin(radians), Math.cos(radians), degrees);
     degrees = 100;
     radians = Math.toRadians(degrees);
    System.out.printf("%-10d%-10.4f%-10.4f%-10.4f%-10.4f\n", radians, Math.tan(radians), Math.sin(radians), Math.cos(radians), degrees);
     degrees = 130;
     radians = Math.toRadians(degrees);
    System.out.printf("%-10d%-10.4f%-10.4f%-10.4f%-10.4f\n", radians, Math.tan(radians), Math.sin(radians), Math.cos(radians), degrees);
     degrees = 160;
     radians = Math.toRadians(degrees);
System.out.printf("%-10d%-10.4f%-10.4f%-10.4f%-10.4f\n", radians, Math.tan(radians), Math.sin(radians), Math.cos(radians), degrees);
}

}

展开
收起
小六码奴 2019-10-14 19:08:12 9099 0
1 条回答
写回答
取消 提交回答
  • 您使用打印f进行格式化是错误的。另外,不需要导入扫描仪。度是整数,但是您提供了f而不是d并且还提供了精度4.弧度是两倍。但您提供的d是错误的,我已更正,请检查以下代码。

    public class St_Johns_University { public static void main(String[] args) { System.out.printf("%-10s%-10s%-10s%-10s%-10s\n", "Radians", "Tangent", "Sine", "Cosine", "Degrees");

        int degrees = 60;
        double radians = Math.toRadians(degrees);
        System.out.printf("%-10f%-10.4f%-10.4f%-10.4f%-10d\n", radians, Math.tan(radians), Math.sin(radians), Math.cos(radians), degrees);
         degrees = 80;
         radians = Math.toRadians(degrees);
        System.out.printf("%-10f%-10.4f%-10.4f%-10.4f%-10d\n", radians, Math.tan(radians), Math.sin(radians), Math.cos(radians), degrees);
         degrees = 100;
         radians = Math.toRadians(degrees);
        System.out.printf("%-10f%-10.4f%-10.4f%-10.4f%-10d\n", radians, Math.tan(radians), Math.sin(radians), Math.cos(radians), degrees);
         degrees = 130;
         radians = Math.toRadians(degrees);
        System.out.printf("%-10f%-10.4f%-10.4f%-10.4f%-10d\n", radians, Math.tan(radians), Math.sin(radians), Math.cos(radians), degrees);
         degrees = 160;
         radians = Math.toRadians(degrees);
         System.out.printf("%-10f%-10.4f%-10.4f%-10.4f%-10d\n", radians, Math.tan(radians), Math.sin(radians), Math.cos(radians), degrees);
    }
    

    }

    2019-10-14 19:08:45
    赞同 展开评论 打赏
问答地址:
问答排行榜
最热
最新

相关电子书

更多
函数计算最佳实践:快速开发一个分布式 Puppeteer 网页截图服务 立即下载
低代码开发师(初级)实战教程 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载