浙江大学——零基础学JAVA
1、浮点数判断相等:Math.abs(a-b)<1e-6 取a-b得绝对值判断是否小于极小数
2、取1-100随机整数:(int)Math.random()*100+1 random()取值范围为[0,1)
3、数组名.length:获取数组长度
4、求x的平方根:Math.sqrt(x)
5、逃逸字符:
6、获得某类型的最大最小值: Integer.MIN_VALUE Integer.MAX_VALUE Integer为包裹类型: 7、求绝对值:Math.abs()
8、对小数部分四舍五入:Math.round()
9、求乘方:Math.pow(x,y) x的y次方(浮点数)
10、判断两字符串内容相同:str1.equals(str2)
11、访问String里的字符:str.charAt(index) 返回在index上的单个字符,index的范围是[0,length()-1],不能用for-each遍历
12、字符串切割str.substring(index1,index2【没有默认到最后一位】) 返回index1到index2-1的字符串
13、寻找字符: 14、java中的“指针”:数组
public class test { public static void sort(int[] a) { int temp = a[0]; a[0] = a[1]; a[1] = temp; } public static void main(String[] args) { try (Scanner in = new Scanner(System.in)) { int[] a = new int[2]; a[0] = in.nextInt(); a[1] = in.nextInt(); sort(a); System.out.print(a[0]+" "); System.out.println(a[1]); } } }
上一篇:
IDEA上Java项目控制台中文乱码