基础语法关键字

基础语法

注释

Java语言的三种注释

//当行快捷ctrl+/

/**/多行注释 ctrl+shift+/

/*** */文档注释,用于类,方法(函数),属性功能说明

关键字

关键字中所有字母都为小写

用于定义数据类型的关键字

class interface enum byte short int long float double char boolean void

定义数据类型

true false null

用于定义流程

if else switch case default while do for break continue return

定义访问权限

private protected public

定义类,函数,变量修饰符的关键字

abstract final static synchronized

用于定义类与类之间关系的关键字

extends implements

用于定义建立实例,判断实例的关键字

new this super instanceof

用于异常的关键字

try catch finally throw throws

其他修饰符关键字

native strictfp transient volatile assert

保留字

goto 、const

标识符

规则

  • 26个字母大小写 0-9,_或$组成,数字不能开头

  • 不可以使用关键字和保留字,但能包含

  • Java中严格区分大小写,长度无限制

  • 不可以包含空格

  • 见名知意

    Java中的名称命名规范

    包名:多单词组成字母都小写

    类名,接口名:多单词时,所有的首字母大写

    变量名,方法名,第一个第一个小写,后面单词首字母大写

    常量名:全部大写

练习

import java.util.Scanner;
public class two1 {
​
    public static void main(String[]args){
        //体验i++和++i
           int i1 = 10,i2 = 20;
            int i = i1++;
            System.out.print("i="+i);
            System.out.println("i1="+i1);
            i = ++i1;
            System.out.print("i="+i);
            System.out.println("i1="+i1);
        //体验=和==
            boolean b1=false;
            if(b1=true){
                    System .out .println("结果为真");
            }else
                System.out.println("结果为假");
        //体会移位符
        int i=1;
        i*=0.1;
        System.out.println(i);
        i++;
        System.out.println(i);
        //交换数字
   int a=5,b=10;
   a=b;
   b=a/2;
   System.out.println(a);
   System.out.println(b);
        //温度转换
        System.out.println("输入一个数字");
        Scanner scan=new Scanner(System.in);
        double a=scan.nextDouble();
        double b=a*9/5+32;
        System.out.print(b);
        //字符转换
char c='A';
        char s=(char)(c+32);
        System.out.print(s);
}
}
​
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值