首页 > 技术文章 > 第二次作业——胡智凯

212006240hzk 2022-01-23 22:30 原文

这个作业属于哪个课程 https://edu.cnblogs.com/campus/fzzcxy/softwaredevelopment
这个作业要求在哪里 https://edu.cnblogs.com/campus/fzzcxy/softwaredevelopment/homework/12438
这个作业的目标 了解java,掌握java基础语法
学号 212006240

1、了解java

java程序要先写一个test.java程序,后编译为test.class才能够运行,test.class的运行需要jvm(java虚拟机)的支持,jvm包含在jdk中

2、基础语法

//java 基础语法
//记得用gbk编码
// 表示test是一个类,是一个public共有的类
public class test
{
        //编写一个main方法,既程序的入口
        int ab;//全局变量
        public static void main(String[] args) 
        {
            //局部变量

            int a; //变量声明
            a = 10; //变量赋值
            System.out.println(a);//输出变量(类似于c++"cout >>")
            float f;
            double b;//浮点数
            char c;//字符    
            String s = "hello world";//字符串
            boolean bo = true;//布尔类型
            System.out.println(s);
            System.out.println("hello world");//输出hello world
            byte by;

            //强制类型转换

            int i = (int)1.9;
            String s1 = "123";
            int i1 = Integer.parseInt(s1);//字符串转整数


            //选择,循环

            if(a == 1){
                System.out.println(a);
            }

            while (a == 1){
                System.out.println(a);
                a ++;
            }
            do {
                System.out.println(a);
                a ++;
            }
            while (a == 1);
            //算数运算符 +  -  *  /  %  ++  -- 
        //关系运算符 ==  !=  <  >  <=  >=  instanceof(暂时不用了解)

        //逻辑运算符 
        //  &(逻辑与,前后都执行)  &&(短路与,若前一个为假,则后一个不执行)
        //  |(逻辑或,前后都执行)  ||(短路或,若前一个为真,则后一个不执行)
        //  !(取反)  ^(异或)

        //三元运算符 a ? b : c  (若a为真,则执行b,若a为假,则执行c)

        //2进制(0b) 8进制(0) 16进制(0x)

        //位运算符 &(按位与) |(按位或) ^(按位异或) ~(按位取反)

        //位运算符 <<(1<<2 = 4 本质为1*2*2 = 4)  >>(1 >> 2 = 0 本质为1 / 2 / 2 = 0)  
        // >>>(逻辑右移)

        //数组
        int i2[];
        i2 = new int [10];

        }

        
        
    ```
    
    
    
}

推荐阅读