目录
一、常用快捷键
二、常用小功能
1、Scanner类
2、equals使用
3、随机数Math.random()用法
4、Math函数—算数计算
5、Math函数—进位
main→Alt+/ 生成一个main主函数
syso→Alt+/ 生成一个“System.out.println("");”语句
Ctrl+Shift+F 代码缩进的统一规范
Ctrl+/ (取消)单行注释
Ctrl+Shift+/ 多行注释
Ctrl+Shift+\ 取消多行注释
Ctrl+D 删除某行代码
Ctrl+F 查找/替换关键词
Ctrl+Z 撤销当前操作,恢复到上一步操作
Ctrl+Y 取消撤销,恢复当前一步的操作,与Ctrl+Z功能相反
Ctrl+L 转到第多少行,对于报错时可以快速定位到报错位置
当我们需要使用键盘输入数据时,这时候就需要我们创建一个Scanner键盘录入对象;
使用步骤如下:
(1)导包(三种方法)
方法1:import java.util.Scanner;或import.java.util.*;
方法2:右击鼠标导包
方法3:使用“Ctrl+Shift+O”快捷键
(2)创建Scanner对象
Scanner input = new Scanner(System.in);
(3)创建键盘录入对象input调用方法来获取数据
input.nextInt(); //获取int类型数据;
input.nextDouble(); //获取Double类型数据;
input.next(); //获取String类型数据;
public static void main(String[] args) {
//创建Scanner对象
Scanner input=new Scanner(System.in);
//获得键盘输入的数据
int num=input.nextInt();
//打印输出您输入的
System.out.println("您输入的整数是:"+num);
//关闭键盘
input.close();
}
equals是在object类中的方法,在object中equals是用来看看两个参数是否引用的是同一个对象
源码:
public boolean equals(Object obj) {
return (this == obj);
}
用法:boolean result=字符串1.equals(字符串2);
返回一定是个Boolean类型的值
Math.random():随机返回一个[0.0,1.0)的double类型数据 ;
(int)Math.random()*10:随机返回一个[0,10)的int类型数据 ;
(int)(Math.random()*(num2-num1)+num1):随机返回一个[num1,num2)的int类型数据 (num1
Math.sqrt()
:计算平方根
Math.cbrt()
:计算立方根
Math.pow(a,b)
:计算a的b次方
Math.max( , )
:计算最大值
Math.min( , )
:计算最小值
Math.abs()
:取绝对值
public static void main(String[] args) {
System.out.println(Math.sqrt(16)); // 4.0
System.out.println(Math.cbrt(8)); // 2.0
System.out.println(Math.pow(3, 2)); // 9.0
System.out.println(Math.max(2.3, 4.5));// 4.5
System.out.println(Math.min(2.3, 4.5));// 2.3
/**
* abs求绝对值
*/
System.out.println(Math.abs(-10.4)); // 10.4
System.out.println(Math.abs(10.1)); // 10.1
}
Math.ceil()
:天花板的意思,就是逢余进一
Math.floor()
:地板的意思,就是逢余舍一
Math.rint()
:四舍五入,返回double值。注意.5的时候会取偶数
Math.round()
:四舍五入,float是返回int,double时返回long值
/**
* ceil天花板的意思,就是逢余进一
*/
System.out.println(Math.ceil(-10.1)); // -10.0
System.out.println(Math.ceil(10.7)); // 11.0
System.out.println(Math.ceil(-0.7)); // -0.0
System.out.println(Math.ceil(0.0)); // 0.0
System.out.println(Math.ceil(-0.0)); // -0.0
System.out.println(Math.ceil(-1.7)); // -1.0
System.out.println("-------------------");
/**
* floor地板的意思,就是逢余舍一
*/
System.out.println(Math.floor(-10.1)); // -11.0
System.out.println(Math.floor(10.7)); // 10.0
System.out.println(Math.floor(-0.7)); // -1.0
System.out.println(Math.floor(0.0)); // 0.0
System.out.println(Math.floor(-0.0)); // -0.0
System.out.println("-------------------");
/**
* rint 四舍五入,返回double值 注意.5的时候会取偶数 异常的尴尬=。=
*/
System.out.println(Math.rint(10.1)); // 10.0
System.out.println(Math.rint(10.7)); // 11.0
System.out.println(Math.rint(11.5)); // 12.0
System.out.println(Math.rint(10.5)); // 10.0
System.out.println(Math.rint(10.51)); // 11.0
System.out.println(Math.rint(-10.5)); // -10.0
System.out.println(Math.rint(-11.5)); // -12.0
System.out.println(Math.rint(-10.51)); // -11.0
System.out.println(Math.rint(-10.6)); // -11.0
System.out.println(Math.rint(-10.2)); // -10.0
System.out.println("-------------------");
/**
* round 四舍五入,float时返回int值,double时返回long值
*/
System.out.println(Math.round(10)); // 10
System.out.println(Math.round(10.1)); // 10
System.out.println(Math.round(10.7)); // 11
System.out.println(Math.round(10.5)); // 11
System.out.println(Math.round(10.51)); // 11
System.out.println(Math.round(-10.5)); // -10
System.out.println(Math.round(-10.51)); // -11
System.out.println(Math.round(-10.6)); // -11
System.out.println(Math.round(-10.2)); // -10
其他常用小技能后期不断更新...................
码文不易,本篇文章就介绍到这里,如果想要学习更多Java系列知识,请关注博主,博主带你零基础学习Java知识。与此同时,对于日常生活有困扰的朋友,欢迎阅读我的第四栏目:《国学周更—心性养成之路》,学习技术的同时,我们也注重了心性的养成。