1、java容易忘记的基础语法知识

1final声明常量,常量全是大写,一旦定义不能改变
final String LOVE = 'haa'

2比较运算符在java
>  <  >=  <= 只支持左右两边操作数是数值类型
==  != 两边的操作数既可以是数值类型也可以是引用类型


3获取用户输入的值
3.1 import java.util.Scanner 
3.2 创建Scanner对象
Scanner input = new Scanner(System.in);
   int num = input.nextInt();#字符串:input.next()   浮点:input.nextDouble() ...

4数组
4.1 定义数组
int[] scores = { 78, 93, 97, 84, 63 };
等价于
int[] scores = new int[]{ 78, 93, 97, 84, 63 };
int scores[] = { 78, 93, 97, 84, 63 };
int scores[] = new int[3];
4.2 遍历数组foreach
for(int score : scores){
    System.out.println(score);
}
4.3 二维数组
4.3.1 定义二维数组
int[][] tmp = new int[2][3]
int tmp[][] = new int[2][3]
int[][] tmp = {{1,2},{3,4}...}
4.3.2 赋值
x[0][1] = 12
4.3.3 遍历二维数组
int[][] scores ={{3,4},{1,2}};
for(int[] score : scores){
    for(int x : score){
        System.out.println(x);
    }
}
4.4 数组常用属性
4.4.1 length: int[] scores = { 78, 93, 97, 84, 63 }; scores.length
4.5 数组常用方法
import java.util.Arrays
4.5.1 : Arrays.sort(arr)
4.5.2 : Arrays.toString(arr):
int[] scores = new int[]{ 78, 93, 97, 84, 63 };
System.out.print(Arrays.toString(scores)); //[78, 93, 97, 84, 63]




5方法
5.1 方法声明
无返回值public void test(int a,String[] b){} ,如果声明了void方法体中就不能有return
有返回值public int test(int a,String[] b){ return 2} 如果生命了int返回值就一定要是int


5.2 方法重载同一个类中方法名相同参数个数不同或位置不同或类型不同根据参数个数决定调用哪个方法
public void test(){}
public void test(int a){}
public void test (String a){}
public void test(int a ,int b){}



  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值