`//导入util包 import java.util.; //导入Math方法包 import static java.lang.Math.;
public class index {
public static final int YY = 0;
// 类常量(class constant<'ka:nstent>)
// 访问修饰符:[public] (公共的) <'pAblIk>; 关键字:[static final] (静态常量) <'staetIk 'faInl>;
// 类型(Type):[int]; 标识符(Identifier<ai'dentifaier>):[YY]; 赋值运算符:[=];
// 值(value<'vaelju:>):[0]
public static void main(String[] args) {
// IfandFor();
// in();
// change();
math();
}
public static void type(String[] args) {
// Java是强类型语言,所以必须给每个变量声明一种类型。
// Java的类型:
// int 整型 取值范围:-2 147 483 648 ~ 2 147 483 647 (常用)
// short 短整型 取值范围:-32 768 ~ 32 767
// long 长整型 取值范围:-9 223 372 036 854 775 808 ~ 9 223 372 036 854 775 807
// byte 比特 取值范围:-128 ~127 (知道就行)
// float 浮点数 取值范围:大约 +- 3.402 823 47E+38F (有效位数:6 ~ 7)
// double 双精度浮点数 取值范围:大约 +- 1.797 693 134 862 315 70E+308 (有效位数;15)
// char 字符型
// boolean 布尔值
}
//数据类型的强制转换
public static void change (){
//语法:(要转换的类型) 要转换的变量
//【注意】强制转换string类型要用其他方法
//下方展示的是双精度浮点数强制转换为整数型
double flo = 2.5;
int nmb = (int) flo;
System.out.println(nmb); // 2
}
//Math方法的使用
public static void math(){
//在此文件的顶部导入了一个静态Math包,因此使用数学函数就不再需要添加'Math'前缀
double sin1 = sin(2);
System.out.println(sin1);
}
public static void IfandFor() {
if (0 > -1) {
System.out.println(true);
} else {
System.out.println(false);
}
for (int i = 0; i < 7; i++) {
System.out.println(i);
}
}
// 标准输入流
public static void in (){
//构造Scanner对象
Scanner in = new Scanner(System.in);
System.out.println("请输入您的姓名:");
//读取一条输入(string)
String name = in.nextLine();
System.out.println("请输入您的年龄:");
//读取一条输入(int)
int age = in.nextInt();
System.out.println("请输入您的身高(单位/m):");
//读取一条输入(double)
double height = in.nextDouble();
//输出输入的字符串和数字
System.out.println("姓名:" + name +"\n"+ "年龄:" + age + "\n" + "身高:" + height + "m");
}
}`