首页 > 编程语言 > 详细

Java Cheatsheet

时间:2016-01-23 07:55:52      阅读:190      评论:0      收藏:0      [点我收藏+]

Hello, World.

public class learn {
    public static void main(String[] args){
        System.out.println("hi");
    }
}

 

Built-in data types:

int, double, boolean, char, String

 

类型转换:

字符串转为数字: 

        String s1 = "1234";
        String s2 = "1234.123";
        
        int a = Integer.parseInt(s1);
        double b = Double.parseDouble(s2);
        long c = Long.parseLong(s1);
        
        System.out.println(a); //1234
        System.out.println(b); //1234.123
        System.out.println(c); //1234

 

数字转换成字符串:

        double d = 123.4;
        String s = String.valueOf(d);
        System.out.println(s); //123.4

 

字符串加数字, 生成字符串

"1234"+99 --> "123499"

 

Switch:

switch(day){
  case 0: System.out.println("Sun"); break;
  case 1: System.out.println("Mon"); break;
  
}

 

数组:

double[] b = new double[N];

 

Input:

Scanner in=new Scanner(System.in);
String readLine = in.nextLine();
System.out.println(readLine);

 

字符串长度:

s.length()

Java Cheatsheet

原文:http://www.cnblogs.com/XingyingLiu/p/5152771.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!