javase学习小结二
三角函数方法
Math.sin(radians):Math.sin(Math.PI/6)=0.5
Math.cos(radians):Math.cos(Math.PI/3)=0.5
Math.tan(radians):Math.tan(Math.PI/3)=1.732
Math.toRadians(degrees):Math.toRadians(30)=Math.PI/6=0.5236
Math.toDegrees(radians):Math.toDegrees(Math.PI/2)=90.0
Math.asin(a):Math.asin(0.5)=Math.PI/6=0.52359877
Math.acos(a):Math.acos(0.5)=Math.PI/3=1.0471975511965979
Math.atan(a):Math.atan(1.0)=Math.PI/4=0.7853981633974483
指数函数方法
Math.exp(1)=Math.E=2.718281828459045
Math.log(Math.E)=1.0
Math.log10(10)=1.0
Math.pow(2,3)=8.0
Math.sqrt(4)=2.0
取整函数方法
Math.ceil(x):Math.ceil(4.4)=5.0或Math.ceil(4.6)=5.0
Math.floor(x):Math.floor(4.4)=4.0或Math.floor(4.6)=4.0
Math.round(x):四舍五入即Math.round(4.4)=4或Math.round(4.6)=5
Math.rint(x):返回一个距离最近的整数,如果距离相等返回最近的偶数。Math.rint(4.4)=4.0或Math.(4.5)=4.0(偶数)或Math.rint(4.6)=5.0
min、max和abs方法
Math.min(2,4)返回2,Math.min(2,4.0)返回2.0
Math.max(2,3)返回3,Math.max(2.0,3)返回3.0
Math.abs(-2)返回2,Math.abs(-2.0)返回2.0
random方法
0.0<=Math.random()<1.0
(int)(Math.random()*10)返回0~9之间的一个随机整数
50+(int)(Math.random()*50)返回50~99之间的一个随机整数
50.0<=50+Math.random()*50<100
Character类方法
Character.isDigit('0~9')返回ture,Character.isDigit('a')返回false或Charcter.isDigit('A')返回false
Character.isLetter('a')返回true,Character.isLetter('A')返回true,Character.isLetter('9')返回false
Character.isLetterOrDigit('a')返回true,Character.isLetterOrDigit('A')返回true,Character.isLetterOrDigit('0~9')返回true
Character.isLowerCase('a')返回true,Character.isLowerCase('A')返回false,Character.isLowerCase('8')返回false
Character.isUpperCase('A')返回true,Character.isUpperCase('a')返回false,Character.isUpperCase('8')返回false
Character.toLowerCase('A')返回a,Character.toLowerCase('a')返回a,Character.toLowerCase('8')返回8
Character.toUpperCase('a')返回A,Character.toUpperCase('A')返回A,Character.toUpperCase('@')返回@
String对象的简单方法
"字符串".length()返回字符串中的字符数
"字符串".charAt(index)返回字符串中指定位置的字符(index从0开始)
"字符串A".concat("字符串B")返回"字符串A字符串B"
"字符串".toLowerCase()返回"字符串小写"
"字符串".toUpperCase()返回"字符串大写"
"字符串".trim()返回一个新"字符串",去掉两边的空白字符,空白字符包括:空格、\t、\f、\r、\n
System.out.println("Good good study,
day day up!");语句错误,字符串常量不能串行,要串行必须加‘+’
String对象的比较方法
"A".equals("A")返回true,"A".equals("B")返回false
"A".equalsIgnoreCase("a")返回true,"A".equalsIgnoreCase("b")返回false
"A".compareTo("B")返回-1,"B".compareTo("A")返回1,"A".compareTo("A")返回0,"A".compareTo("a")返回-32
"A".compareToIgnoreCase("a")返回0,"A".compareToIgnoreCase("b")返回-1,"B".compareTo("a")返回1
"AB".startsWith("A")返回true,"AB".startsWith("")返回true,"AB".startsWith("B")返回false,"AB".startsWith("aB")返回false
"AB".endsWith("B")返回true,"AB".endsWith("")返回true,"AB".endsWith("A")返回false,"AB".endsWith("Ab") 返回false
"ABC".contains("AB")返回true,"ABC".contains("BC")返回true,"ABC".contains("AC")返回false,"ABC".contains("")返回true
String对象获取子字符串的方法
"ABCD EFGH IJKL".substring(5)返回"EFGH IJKL"
"ABCD EFGH IJKL".substring(5,9)返回"EFGH"
String对象获取字符串中的字符所在的索引值的方法
indexOf(ch):返回字符串中出现的第一个ch的下标,如果没有,返回-1
indexOf(ch,fromIndex):返回字符串fromIndex之后出现的第一个ch的下标,如果没有,返回-1
indexOf(s):返回字符串中出现的第一个字符串s的下标,如果没有,返回-1
indexOf(s,fromIndex):返回字符串中fromIndex之后出现的第一个字符串s的下标,如果没有,返回-1
lastIndexOf(ch):返回字符串中出现的最后一个ch的下标,如果没有,返回-1
lastIndexOf(ch,fromIndex):返回字符串fromIndex之前出现的最后一个ch的下标,如果没有,返回-1
lastIndexOf(s):返回字符串中出现的最后一个字符串s的下标,如果没有,返回-1
lastIndexOf(s,fromIndex):返回字符串中fromIndex之前出现的最后一个字符串s的下标,如果没有,返回-1
假设一个字符串s包含使用空格分开的姓和名,使用下面代码可以抽取姓和名:
int k = s.indexOf(" ");
String firstName = s.substring(0,k);
String lastName = s.substring(k+1);
字符串与数字间的转换
int intValue = Integer.parseInt("123");
double doubleValue = Double.parseDouble("123.456");
String s = 123+"";System.out.println(s);输出结果为字符串123
System.out.println("Welcome "+('\u0001'+1))输出结果为Welcome 2
System.out.println("Welcome "+1+1)输出结果为Welcome 11
System.out.println("Welcome "+'a'+1)输出结果为Welcome a1
System.out.println('a'+1+" Welcome")输出结果为98 Welcome
Scanner对象的方法
java.util.Scanner input = new java.util.Scanner(System.in);
input.next()读取以空白字符结束的字符串(' ','\t','\f','\n','\r')
input.nextLine()读取以按下回车键为结束标志的字符串
For example:
java.util.Scanner input = new java.util.Scanner(System.in);
System.out.print("Enter three words separated by spaces: ");
String s1 = input.next();
String s2 = input.next();
String s3 = input.next();
System.out.println(s1);
System.out.println(s2);
System.out.println(s3);
Displays:
Enter three words separated by spaces: Welcome to java
Welcome
to
java
For example:
java.util.Scanner input = new java.util.Scanner(System.in);
System.out.print("Enter a line: ");
String s = input.nextLine();
System.out.println("The line entered is "+s);
Displays:
Enter a line: Welcome to java
The line entered is Welcome to java
为了避免输入错误,不要在nextByte()、nextShort、nextInt()、nextLong()、nextFloat()、nextDouble()和next()之后使用nextLine()
javase学习小结二的更多相关文章
- python --- 字符编码学习小结(二)
距离上一篇的python --- 字符编码学习小结(一)已经过去2年了,2年的时间里,确实也遇到了各种各样的字符编码问题,也能解决,但是每次都是把所有的方法都试一遍,然后终于正常.这种方法显然是不科学 ...
- Vue学习小结(二)
接上一批,小结(二). 三.导航内容(含左侧导航及顶部面包屑导航) 其实导航条主要根据element-ui的教程进行编写,官网:http://element-ui.cn/#/zh-CN/compone ...
- JavaSE学习(二):进制转换—数据类型转换—Java运算符
一.进制转换 1.1 其他进制转十进制(以十六进制为例): 十六进制范围:0-9, A-F对应数字10-15 2A7E(16) = 14*16(0) +7*16(1) + 10*16(2) + ...
- Maven学习小结(二 项目构建过程)
1.创建Maven项目 1.1 创建Maven项目的约定目录结构 1.2 编辑pom.xml <project xmlns="http://maven.apache.org/POM/4 ...
- javase学习小结三
格式标识符: System.out.printf("%d,%f,%5d,%-9.4f,%%,%13e",67,78.9,89,78.9,567.345); 输出结果为:67,78. ...
- javase学习小结一
输出格式: int num=12345; System.out.printf("%7d",number);输出结果为:空格空格12345 System.out.println(&q ...
- Ubuntu学习小结(二)PostgreSQL的使用,进程的查看关闭,编辑器之神Vim入门
距离上次发布文章已经过去了很久.在过去的半年中,虽然写的代码不多,但是在接触了计算机一些其他的知识,包括数据库.网络之后,感觉能够融会贯通,写代码水平又有了一定的提高.接下来,将会发表几篇文章,简单介 ...
- 从零开始学习jQuery (二) 万能的选择器
本系列文章导航 从零开始学习jQuery (二) 万能的选择器 一.摘要 本章讲解jQuery最重要的选择器部分的知识. 有了jQuery的选择器我们几乎可以获取页面上任意的一个或一组对象, 可以明显 ...
- pthread多线程编程的学习小结
pthread多线程编程的学习小结 pthread 同步3种方法: 1 mutex 2 条件变量 3 读写锁:支持多个线程同时读,或者一个线程写 程序员必上的开发者服务平台 —— DevSt ...
随机推荐
- nohup—后端守护进程
要将一个命令放到后台执行,我们一般使用nohup sh command & 为什么要nohup? 因为我用使用Scrt这种终端工具退出的时候会向我们在当前shell下启动的进程发生一个SIGH ...
- UVA 11292 Dragon of Loowater(简单贪心)
Problem C: The Dragon of Loowater Once upon a time, in the Kingdom of Loowater, a minor nuisance tur ...
- AtCoder Grand Contest 013
这场打得蛮菜的,很晚才出BC,还一堆罚时…… A - Sorted Arrays 题目大意:将给定数列划分成单调不增或单调不减的区间,求最少区间数. 贪心即可. #include<cstdio& ...
- Slim Span(Kruskal)
题目链接:http://poj.org/problem?id=3522 Slim Span Time Limit: 5000MS Memory Limit: 65536K Total Subm ...
- ECharts插件的使用
ECharts插件:官网下载echarts.js开发者可以选择源码.下载地址:http://echarts.baidu.com/download.html 下载之后,echarts.js放在js文件夹 ...
- Oracle:控制语句 IF..ELSIF语句、CASE语句、FOR循环语句
--多重if语句(注意点:BEGIN END ,IF 条件 THEN,ELSIF 条件 THEN,ELSE... END IF)BEGIN IF FALSE THEN DBMS_OUTPUT.put_ ...
- Lnmp修改php.ini配置
http://www.chenruixuan.com/archives/341.html A-A+ 陈瑞轩2014年5月8日07102 次浏览PHP | 工作 要在lnmp系统里面修改php.ini配 ...
- ublime Text 3安装与使用
ublime Text 3安装与使用 工具 2015-07-30 10:46 0 34 工欲善其事,必先利其器.好的工具帮助我们节省大量的工作时间,好用的插件使工具更强大. 1. 下载 可以从官网 h ...
- Oracle临时表空间组
Oracle 10g之前,同一用户的多个会话只可以使用同一个临时表空间,因为在给定的时间只有一个临时表空间默认给用户,为了解决这个潜在的瓶颈,Oracle支持临时表空间组即包含多个临时表空间的集合.临 ...
- Jmeter下载时Binaries和Source两类包的区别
在下载Jmeter时,存在两种类型的下载包,分别为Binaries和Source: 一般开放原代码软件都会有两个版本发布: Source Distribution 和 Binary Distribut ...