java打印正弦曲线示例
时间:2022-05-04 00:48:56
/*
* 绘制0°到360°的正弦曲线
* 分两种情形,y>0和y<=0进行绘制
* 每种情形中要考虑每行打印两个"*"字符
* 并在打印第二个"*"字符后换行
*/
package hundred;
import java.lang.Math;
public class SinTest {
public static void main(String[] args){
//y为列方向,值从1到-1,步长为0.1
for (double y = 1;y>=-1;y-=0.1){
//计算出y对应的弧度,乘10为图形放大倍数
int m = -(int)(Math.asin(y)*10);
if (y > 0){
for (int x = 1;x <1-m;x++){
System.out.print(" ");
}
System.out.print("*");
//31为10*π的整数部分,打印出来的曲线比较顺眼
for (int x =1;x <31+2*m;x++){
System.out.print(" ");
}
System.out.println("*");
}
if (y <= 0){
for (int x = 1;x < 32+m;x++){
System.out.print(" ");
}
System.out.print("*");
//31为10*π的整数部分,打印出来的曲线比较顺眼
for (int x = 1;x < 31-2*m;x++){
System.out.print(" ");
}
System.out.println("*");
}
}
}
}
标签:java,数组
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Spring内存缓存Caffeine的基本使用教程分享
2023-05-26 00:30:33
基于Beanutils.copyProperties()的用法及重写提高效率
2023-04-20 12:10:25
![](https://img.aspxhome.com/file/2023/8/85568_0s.jpg)
java request.getHeader("user-agent")获取浏览器信息的方法
2022-05-28 01:04:26
![](https://img.aspxhome.com/file/2023/6/125336_0s.png)
C#使用Process类调用外部程序分解
2022-01-07 16:34:11
Java基于swing实现的弹球游戏代码
2023-09-15 05:13:49
![](https://img.aspxhome.com/file/2023/8/116198_0s.jpg)
SpringBoot使用POI进行Excel下载
2022-06-14 13:16:13
android studio 3.0 升级 项目遇到的问题及更改思路(问题小结)
2021-06-14 17:19:16
![](https://img.aspxhome.com/file/2023/4/91644_0s.png)
Java线程安全中的有序性浅析
2023-07-12 03:07:58
![](https://img.aspxhome.com/file/2023/4/96114_0s.png)
Java的MD5工具类和客户端测试类
2022-04-23 03:08:48
Java二维数组实现数字拼图效果
2021-11-21 20:39:17
SpringBoot2整合Ehcache组件实现轻量级缓存管理
2022-06-18 18:11:16
SpringBoot统一处理功能实现的全过程
2022-12-24 09:43:26
Java9的一些新特性介绍
2022-03-29 04:13:58
springboot对接支付宝支付接口(详细开发步骤总结)
2023-11-10 23:07:35
![](https://img.aspxhome.com/file/2023/6/58746_0s.png)
ShardingSphere解析SQL示例详解
2023-11-23 13:57:55
Android APK应用安装原理解析之AndroidManifest使用PackageParser.parserPackage原理分析
2023-05-19 23:58:18
![](https://img.aspxhome.com/file/2023/9/111699_0s.jpg)
Java ByteBuffer网络编程用法实例解析
2022-09-17 20:16:22
![](https://img.aspxhome.com/file/2023/5/107555_0s.jpg)
MyBatis中使用foreach循环的坑及解决
2023-11-02 12:47:51
Java获取字符串编码格式实现思路
2023-08-14 12:35:38
Java精品项目瑞吉外卖之员工信息管理篇
2023-07-29 07:43:36
![](https://img.aspxhome.com/file/2023/9/81939_0s.png)