
ajjrx - 云代码空间
—— Habit is the love.
public class Hello{
public static void main(String[] args){
double root = Math.sqrt(17.0);//首先计算圆括号中的表达式,也被称为函数的参数,然后计算函数(方法)本身的值
System.out.println(root);
double angle = 1.5;
double height = Math.sin(angle);//在Java中,传给sin等三角方法的参数为弧度值。
System.out.println(height);
double degrees = 90.0;
angle = degrees / 360.0 * 2 *Math.PI;//弧度值 = 角度除以360°,再乘以2π,其中π Java提供了Math.PI来表示(PI是一个变量名,而不是方法,因此PI后面不需要参数)
System.out.println(angle);
//int x = Math.round(Math.PI * 20.0);//错误:不兼容的类型:从long转换到int可能会有损失
System.out.println(Math.round(Math.PI * 20.0));//round函数将double转换为离其最近的int整型数(计算结果为63)
//round方法的实质是数据 + 0.5然后向下取整。
double y = Math.exp(Math.log(Math.E*Math.E));//在Java中,log方法总是以e为底数。将2作为指数计算幂(e的2次方) Math.E表示自然常数e
System.out.println(y);
}
}
public class NewLine{
public static void newLine(){//newLine的实际上的用处在于跳过下一行
System.out.println("");
}
public static void threeLine(){//threeLine的实际上的用处在于跳过三行
newLine();//可以多次调用同一个方法
newLine();//在一个方法中调用另一个方法
newLine();//将程序分解为方法有好处
}
public static void main(String[] args){
System.out.println("First line.");
threeLine();
System.out.println("Second line.");
}
}