首先round和flour都是属于java.lang.Math类里面的方法
round()方法就是四舍五入
但是注意啦,round(-3.5)结果是-3,round(-3.6)结果-4,round(3.5)结果是4
flour()比较像求一个数的下界,比如-3.6就是-3
字符串:
1.子串:主要使用substring(x,y)方法,x是字符串从那个位置读取,y是读取到的位置,其子串长度就是y-x
String e = "hello ";
String s = e.substring(1, 3);
s就是“el”
2.拼接:+
3.不可变字符串:java中字符串是不可改变的,但是可以拼接,编译器通过字符串共享提高效率
4.字符串是否相等:e.equals(s),相等返回true,不等就是false,值得注意的是,这里的e和s既可以是字符串变量也可以是常量
"asd".equals(s)
忽略大小写比较字符串需要使用equalsIqnoreCase
"Asd".equalsIgnoreCase("asd")
最最值得注意的就是比较不能使用 == 比较,因为虽然字符串是共享的,但是==是针对是不是放在同一个地方来解释的,所以就算同样的“hello”也可能不在同一个位置,而且拼接和子串产生的结果并不是共享的
5.空串和NUll串
使用str.lenth()判断是不是空串,str也可以是常量
java中可以存放null(java中特别注意大小写)
也就是要检查if(str!=null&&str.length()!=0)
6.代码点
String e = "hello ";
int q = e.codePointCount(0,e.length());
char w = e.charAt(2);
w就是l
7.字符串api
"d".compareTo("a")结果是3,
string u = e.replace(e,"b"); 结果u就是b
字符串大小写变化:
字符串小写变大写:e.toUpperCase()
字符串大写变小写:e.toLowerCase()
8.构建字符串
StringBuilder build = new StringBuilder();
build.append('c');
build.append("str");
String o = build.toString();
结果就是cstr
9.字符串输入
Scanner in = new Scanner(System.in);
String name = in.nextLine();//输入一行,可以读取空格
String name = in.next();//读取一个单词,以空白符作为分隔
int name = in.nextInt();输入整数
10.格式输出
System.out.printf("%,.2f",100000000.0/3.0); 33,333,333.33
System.out.printf("%6.2f",1000.0/3.0); 333.33
System.out.printf("%tc",new Date()); 星期一 二月 29 21:15:38 CST 2016