Java 基础
一.注释
1.代码复杂时可以看懂自己写了什么
2.书写注释是一个很好的习惯
注释类型
1.单行注释 代码后面加 //+注释
2.多行注释 代码换行/* * /
3.文档注释 代码末尾加/** * /
注释作用
1.注释不会被编译,用来看懂。
public class Main{
public static void main (String []args){
System.out.print("hello world"); //打印你好世界
/*编写多行注释
123646423748 1·3872143287562387942391 */ }
}
/**author xfy
* aust student 20261102 * 好舒服 全部都成功了
*/
二.标识符
1.命名不能以关键字命名
2.命名不能以数字特殊符号命名,不包括下划线
3.命名不能有空格
三.数据类型
1.Java严格规定数据类型必须先定义再输出
public class Main{
public static void main(String []args){
String a="xfy"; //string只能定义变量为非数字的
int b=15; //int 定义数字变量
System.out.print(a);
System.out.print(b);
}
}
![[Pasted image 20261103193620.png]]
public class Main{
public static void main(String []args){
//整数类型 byte int short long int a=10; //最常用
byte b=15;
long c=20L; //需要在后面加一个L
short d=25;
//浮点数 小数类型 float double float e=0.1F; //需要在后面加一个F
double f=0.2; //最常用
//字符型 char 每次只能插入一个字符 需要单引号'
char g='x';
//字符串 string 需要双引号“ S还有大写
String k="xfy";
//布尔型boolean 代表是非对错
boolean xfy=true;
System.out.print(a);
}
}
四.变量的类型转换 #现在最为难理解的
public class Main{
public static void main(String []args){
byte a=100;
int b=a;
//强制转换类型
int c=10000000;
byte d=(byte)c;
System.out.print(b);
System.out.print(d);
/**
* author@xfy * data 2026/11/03 20:37
* palace aust 天工南402
*/ }
}

浙公网安备 33010602011771号