String
Scanner
- /**
- * Filename: TestString.java
- * Description:
- * Copyright: Copyright (c)2014
- * Company: SENRSL
- * @author: senRsl senRsl@163.com
- * @version: 1.0
- * Create at: 2014年4月28日 下午2:30:14
- *
- * Modification History:
- * Date Author Version Description
- * ------------------------------------------------------------------
- * 2014年4月28日 senRsl 1.0 1.0 Version
- */
- package com.dc.test.core7th;
- /**
- *
- *
- * @ClassName: TestString
- * @author senRsl
- *
- * @Package: com.dc.test.core7th
- * @CreateTime: 2014年4月28日 下午2:30:14
- *
- */
- public class TestString {
- public static void main(String[] args) {
- String str = "Abcdefghijklmn";
- System.out.println(str.charAt(3));//提取索引为3
- System.out.println(str.codePointAt(3));//unicode 代码点 d的ascii为100
- System.out.println(str.offsetByCodePoints(3, 5));//不明觉厉
- System.out.println(str.codePointCount(3, 7));//4
- System.out.println(str.compareTo("cd"));//字典顺序比对,-34
- System.out.println(str.compareTo("A"));//字典顺序比对 13
- System.out.println(str.compareTo("Abcdefghijklmn"));//字典顺序比对 0
- System.out.println(str.startsWith("Abc"));//true
- System.out.println(str.endsWith("mn")); //true
- System.out.println(str.equals("Abcdefghijklmn")); //true
- System.out.println(str.equalsIgnoreCase("abcdefghijKLmn"));//true
- System.out.println(str.indexOf(100));//这个地方是unicode代码单元
- System.out.println(str.indexOf(100,2));
- System.out.println(str.indexOf("g"));//6
- System.out.println(str.indexOf("g",2));//6
- System.out.println(str.lastIndexOf(101));//同上,代码单元 4
- System.out.println(str.lastIndexOf(101,10));//从后往前数10位,查询代码单元101,位置4
- System.out.println(str.lastIndexOf("g"));//6
- System.out.println(str.lastIndexOf("g",10));//6
- System.out.println(str.length());//14
- System.out.println(str.replace("ghi", "xxx"));//abcdefxxxjklmn
- System.out.println(str.substring(5));//fghijklmn
- System.out.println(str.substring(5, 8));//fgh
- System.out.println(str.toLowerCase());//abcdefghijklmn
- System.out.println(str.toUpperCase());//ABCDEFGHIJKLMN
- System.out.println(str.trim());//abcdefghijklmn
- System.out.println(str.concat("bbbbb"));//Abcdefghijklmnbbbbb
- System.out.println(str.contains("bc"));//存在字符串,true
- }
- }
- /**
- * Filename: TestScanner.java
- * Description:
- * Copyright: Copyright (c)2014
- * Company: SENRSL
- * @author: senRsl senRsl@163.com
- * @version: 1.0
- * Create at: 2014年4月3日 下午6:15:39
- *
- * Modification History:
- * Date Author Version Description
- * ------------------------------------------------------------------
- * 2014年4月3日 senRsl 1.0 1.0 Version
- */
- package com.dc.test.core7th;
- import java.util.Date;
- import java.util.Scanner;
- import javax.swing.JOptionPane;
- /**
- * Scanner
- *
- * @ClassName: TestScanner
- * @author senRsl
- *
- * @Package: com.dc.test.core7th
- * @CreateTime: 2014年4月3日 下午6:15:39
- *
- */
- public class TestScanner {
- public static void main(String[] args) {
- System.out.print("格式化输出");
- System.out.printf("%.2f",100000/3.0);
- Scanner s = new Scanner(System.in);
- System.out.println("What's your name?");
- String name = s.nextLine();
- System.out.println("how old are you?");
- int age = s.nextInt();
- System.out.println("hello,"+name+"\n your age is "+age);
- s.close();
- System.out.println(String.format("hello %s,next year you'll be be %d", name,++age));
- String input = JOptionPane.showInputDialog("what's your name?");
- System.out.println("hi,"+input);
- System.out.printf("%tc",new Date());
- System.out.printf("%1$s %2$tB %2$te, %2$tY","\n格式化日期",new Date());
- System.out.printf("%s %tB %<te,%<tY", "\n格式化日期",new Date());
- System.exit(0);
- }
- }
TestCondition
- /**
- * Filename: TestCondition.java
- * Description:
- * Copyright: Copyright (c)2014
- * Company: SENRSL
- * @author: senRsl senRsl@163.com
- * @version: 1.0
- * Create at: 2014年4月28日 下午4:15:20
- *
- * Modification History:
- * Date Author Version Description
- * ------------------------------------------------------------------
- * 2014年4月28日 senRsl 1.0 1.0 Version
- */
- package com.dc.test.core7th;
- import java.math.BigDecimal;
- import java.math.BigInteger;
- import java.math.RoundingMode;
- import java.util.Arrays;
- /**
- * 控制流程
- * 条件语句和循环来确定控制流程
- * @ClassName: TestCondition
- * @author senRsl
- *
- * @Package: com.dc.test.core7th
- * @CreateTime: 2014年4月28日 下午4:15:20
- *
- */
- public class TestCondition {
- public static void main(String[] args) {
- int a = 1;
- {//这是一个块block
- int b = 2;
- System.out.println(a+b);
- }
- //if-else
- //while
- //do-while
- //for
- //swtich
- //goto 保留字,使用带标签的break代替
- //continue,也可带标签
- //大数值
- BigInteger bia = BigInteger.valueOf(100);
- BigInteger bib = BigInteger.valueOf(1);
- BigInteger bic = bia.add(bib); //c = a+b;
- BigInteger bid = bic.multiply(bib.add(BigInteger.valueOf(2)));//d = c* (b+2);
- System.out.println("bic:"+bic+"\tbid:"+bid);
- p(bia.add(bib));//和
- p(bia.subtract(bib));//差
- p(bia.multiply(bib));//积
- p(bia.divide(bib));//商
- p(bia.mod(bib));//余数
- p(bia.compareTo(bib));
- //BigDecimal
- BigDecimal bda = BigDecimal.valueOf(100.02);
- BigDecimal bdb = BigDecimal.valueOf(2);
- p(bda.add(bdb));
- p(bda.subtract(bdb));
- p(bda.multiply(bdb));
- p(bda.divide(bdb));
- p(bda.divide(bdb,RoundingMode.HALF_UP));//普通的四舍五入
- p(BigDecimal.valueOf(10, 5));
- //数组
- //for-each
- int[] smallPrimes = {2,3,4,5,6};//数组初始化器
- smallPrimes = new int[]{17,19,20};//匿名数组
- //数组拷贝,System.arraycopy(src, srcPos, dest, destPos, length);
- //数组排序Arrays.sort(a);
- //多维数组
- //不规则数组
- }
- public static void p(Object s){
- System.out.println(s);
- }
- }
--
senRsl
2014-04-28 17:54
GMT+8 @Beijing Tongzhou
senRsl
2014-04-28 17:54
GMT+8 @Beijing Tongzhou
没有评论 :
发表评论