The code copy is as follows:
/*
* Draw a sine curve from 0° to 360°
* There are two situations: y>0 and y<=0 to draw
* In each case, you should consider printing two "*" characters per line
* and wrap the line after printing the second "*" character
*/
package hundreds;
import java.lang.Math;
public class SinTest {
public static void main(String[] args){
//y is the column direction, the value from 1 to -1, the step size is 0.1
for (double y = 1;y>=-1;y-=0.1){
// Calculate the radians corresponding to y, multiply 10 to the magnification of the figure
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 is an integer part of 10*π, and the printed curve is more smooth
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 is an integer part of 10*π, and the printed curve is more smooth
for (int x = 1;x < 31-2*m;x++){
System.out.print(" ");
}
System.out.println("*");
}
}
}
}