一、Java-IntelliJ Tips 记录
增添:1.Java帮助文档
概述 (Java Platform SE 6) (oschina.net)
2.
向后缩进:选择好代码,按【TAB】
向前缩进:选择好代码,按【shift】+【TAB】
1. 批量修改变量名
双击选中变量名字 然后按shift+F6 即可快速修改
2. system.out.println 的快捷方式
输入sout+Tab键
3.public static void main(String[] args){}
打出m +Tab 即可
4. 多行注释
如果你想用多行注释进行快速注释
使用 Ctrl+ / 取消多行注释也是Ctrl+ /
5. 迅速跳到标亮地方
按键F2
6.快速生成构造函数
快捷键:Alt+inset
二、Java 小知识点记录
1.记录利用表示结束外部循环
public class Sc_switch {
public static void main(String[] args) {
//打印单数
out1: //outloop这个标示是可以自定义的比如outloop1,ol2,out5
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10; j++) {
System.out.println(i+":"+j);
if(0==j%2)
break out1; //如果是双数,结束外部循环
}
}
}
}
2.打印显示一维和二维数组——Arrary.toString()
public class Test01 {
public static void main(String[] args) {
int[] intArray = { 1, 4, 6, 7, 8, 9, 10 };
// 使用Arrays的toString方法打印出数组
System.out.println(Arrays.toString(intArray));
}
}
[1, 4, 6, 7, 8, 9, 10]
如果数组为二维度
import java.util.*;
public class 黄金分割 {
public void printkey(int[][] a){
for (int[] each: a){
System.out.println(Arrays.toString(each));
}
}
public static void main(String[] args) {
int x = 0;
int y = 0;
int[][] a = new int[5][5];
for (int i=0;i<5;i++){
for (int j=0;j<5;j++){
a[i][j]= (int)(Math.random()*100);
}
}
for (int i=0;i<a.length;i++){
for (int j=0;j<a[i].length;j++){
System.out.println("a["+i+"]["+j+"]="+a[i][j]);
}
}
//***************************************************
// 进行显示
for (int[] each: a){ //相当于遍历其每一个一维数组 ,通过tostring进行显示
System.out.println(Arrays.toString(each));
}
//**************************************************8
int temp=a[0][0];
for (int i=0;i<5;i++){
for (int j=0;j<5;j++){
if (a[0][0]<=a[i][j]){
temp=a[i][j];
x = i;
y = j;
}
}
}
System.out.println("最大值:"+temp+"下标x为:"+(x+1)+"下标y为:"+(y+1));
}
显示结果
[18, 38, 11, 63, 58]
[75, 45, 47, 37, 97]
[24, 71, 24, 78, 46]
[66, 8, 59, 3, 87]
[73, 27, 92, 60, 95]
3.带有this的构造方法
public class Hero {
String name; //姓名
float hp; //血量
float armor; //护甲
int moveSpeed; //移动速度
//打印内存中的虚拟地址
public void showAddressInMemory(){
System.out.println("打印this看到的虚拟地址:"+this);
}
public static void main(String[] args) {
Hero garen = new Hero();
garen.name = "盖伦";
//直接打印对象,会显示该对象在内存中的虚拟地址
//格式:Hero@c17164 c17164即虚拟地址,每次执行,得到的地址不一定一样
System.out.println("打印对象看到的虚拟地址:"+garen);
//调用showAddressInMemory,打印该对象的this,显示相同的虚拟地址
garen.showAddressInMemory();
Hero teemo = new Hero();
teemo.name = "提莫";
System.out.println("打印对象看到的虚拟地址:"+teemo);
teemo.showAddressInMemory();
}
}