码迷,mamicode.com
首页 > 编程语言 > 详细

ACM常用的Java代码

时间:2014-10-14 19:07:09      阅读:236      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   io   os   ar   java   for   sp   

 1 import java.util.*;
 2 import java.io.*;
 3 
 4 public class Main {
 5     public static void main(String[] args) throws IOException{
 6         // 计算程序运行时间 
 7         // Arrays
 8         long st = System.currentTimeMillis();
 9         if ("abc" == "abc") System.out.println("Yes1");
10         String str1 = new String("abc");
11         String str2 = new String("abc");
12         if (str1 == str2) System.out.println("Yes2");
13         if (str1.equals(str2)) System.out.println("Yes3");
14         
15         //
16         int[] t = {5, 1, 3, 2, 9};
17         Arrays.sort(t);
18         System.out.println(Arrays.toString(t));
19         int[] s = new int[10];
20         Arrays.fill(s, 33);
21         System.out.println(Arrays.toString(s));
22         // returns ((-insertion point) - 1) if key not exists.
23         System.out.println(Arrays.binarySearch(t, 4));
24         int cnt = 0;
25         for (int i = 1; i < 100000000; i++) {cnt++;}
26         long ed = System.currentTimeMillis();
27         System.out.println("time: " + (ed - st));
28         
29         // 字符串hash
30         String str = new String("hello world");
31         System.out.println("hash Code: " + str.hashCode());
32         
33         // BufferReader缓冲与换行读取功能
34         BufferedReader cin = new BufferedReader(new InputStreamReader(System.in));
35         int sum = 0;
36         String ss = null;
37         while ((ss = cin.readLine()) != null) {
38             sum += Integer.parseInt(ss);
39         }
40         System.out.println("the sum is: " + sum);
41         
42         //
43         
44     }
45 }

 

ACM常用的Java代码

标签:style   blog   color   io   os   ar   java   for   sp   

原文地址:http://www.cnblogs.com/Stomach-ache/p/4024713.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!