软件园学生在线

  • {{ item.name }}
  • 2023试用期

登录与注册

后端零 宋俊儒

  • 202300300005
  • 2023-10-14
  • 0

一、注释
1.单行注释//
2.多行注释/ /
3.javadoc.exe暂时用不到


二、标识符
1.标识符:
用来命名类、方法、变量、常量。有一定的规则
2.命名规范:

public class StudengAge //类、接口
public string studentName //变量、方法
CUR_TERM //常量名

3.变量:
变量指代内存中开辟的储存空间,用于存放运算过程中需要用的数据,必须先声明后使用,相同变量只使用一次,声明变量时用数据类型+变量名

    int age; //声明一个整数变量
    double score; //声明一个双精度浮点数变量
    char grade; //声明一个字符变量
    String name; //声明一个字符串变量
    boolean passed; //声明一个布尔变量(true/false)
``````````````

4.数据类型:byte short int long float double boolean char


------------

***三、运算符***
算术
/ % ++(前置后置优先级不同) -- + - *
关系
== != >= <= 
逻辑
&& || !
赋值
= += -= *= /= %= 

------------

***四、控制语句***
1.键盘输入
 import java.util.Scanner;
 Scanner ne = new Scanner(System.in);
 int i = ne.nextInt;

System.out.println(i);

2.选择
if (condition1){

//条件1为真执行
}else if (condition2){
//条件2为真执行
}else {
//1,2都为假执行
}

3.switch
    Scanner sc = new Scanner(System.in);
    System.out.println("请输入");
    int i = sc.nextInt();
    switch(i){
        case 1:
            System.out.println("星期一");
            break;
        case 2:
            System.out.println("星期二");
            break;
        case 3:
            System.out.println("星期三");
            break;
        default:
            System.out.println("其他");
            break;

4.格式化
   System.out.println("root1="+String.format("%.10f,root1"));
   System.out.println("root2="+String.format("%.10f,root2"));
5.循环
for
    for (int m = 1; m <= 9 ; m++) { // 控制行
        for (int k = 1; k <= m; k++) { // 控制列
            System.out.print(k + "*" + m + "=" + k * m + "\t"); 
        }
        System.out.println();
    }
while

int i = 1;
while (i <= 10) {
System.out.println(i);
i++;
}

do while

int i = 1;
do{// do while至少执行一次,先执行后判断
System.out.println(i);
i++;
}while(i <= 10);

------------

***五、方法***
    int rs = r( 10, 20, 50);
    System.out.println(rs);
public static int r(int a, int b, int c) { // 多个形参用","隔开,不用初始值
    int d = a + b*c;
    return d;
}
方法的重载:多个同名方法,具有同种功能,每个方法具有不同参数类型或参数个数,这些同名方法构成重载关系。

------------

***六、面向对象***
1.先设计类,才能获得对象

public class Phone {
//属性
String brand;
double price;
//行为
public void call() {
System.out.println("手机在打电话");
}

public void playGame() {
    System.out.println("手机在打游戏");
}

}

public class test1 {
public static void main(String[] args) {
// 创建手机的对象 类名 + 对象名 = new 类名()
Phone p = new Phone();
p.brand = "mi";//获取值
p.price = 1999;
System.out.println(p.brand);
System.out.println(p.price);
p.call();//调用方法
p.playGame();
}
}

2.封装:对象代表什么,就封装相应的数据,并提供数据对应的行为
3.构造方法:赋值

------------

***七、数组***
    int[] num = {16, 26, 36, 6, 100};
    int sum = 0;
    for(int i = 0; i < num.length; i++) {
        sum += num[i];
    }
        System.out.println(sum);
------------

***八、继承***
1.从已有的类中派生出新的类,注意父子关系
2.你有一个爹 你有多个儿子 你们都是人

------------
202300300005
202300300005
© 2025 软件园学生在线
Theme by Wing