Java Number & Math 类
全部函数见https://www.runoob.com/java/java-number.html
1 2 3 4 5 6 Math.sin() Math.cos() Math.tan() Math.PI Math.atan() Math.toDegrees()
Java Character 类
Java String 类
创建String对象的基本语法
注意:String 类是不可改变的,所以你一旦创建了 String 对象,那它的值就无法改变了(详看笔记部分解析)。
如果需要对字符串做很多修改,那么应该选择使用 StringBuffer & StringBuilder 类。
1 2 3 4 String str=new String ("Runoob" ); String str = "Runoob" ;
常用方法
1 2 3 4 5 6 7 8 9 10 11 12 13 str.length() "Hello," + " runoob" + "!" str3.compareToIgnoreCase( str1 ) String fs; fs = String.format("浮点型变量的值为 " + "%f, 整型变量的值为 " + " %d, 字符串变量的值为 " + " %s" , floatVar, intVar, stringVar);
Arrays方法
1 2 3 4 5 6 7 8 9 10 11 Arrays Arrays.binarySearch(numbers, key); public static int binarySearch (Object[] a, Object key) public static boolean equals (long [] a, long [] a2) public static void fill (int [] a, int val) public static void sort (Object[] a)
Java 数组
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 datatype[] name; double [] mylist;name=new datatype [size]; dataType[] name = new dataType [arraySize]; for (type element: name){ System.out.println(element); } for (double element: myList) { System.out.println(element); } public static void printArray (int [] array) { for (int i = 0 ; i < array.length; i++) { System.out.print(array[i] + " " ); } } public static int [] reverse(int [] list) { int [] result = new int [list.length]; for (int i = 0 , j = result.length - 1 ; i < list.length; i++, j--) { result[j] = list[i]; } return result; } dataType[][] name = new dataType [size][size]; String[][] s = new String [2 ][]; s[0 ] = new String [2 ]; s[1 ] = new String [3 ]; s[0 ][0 ] = new String ("Good" ); s[0 ][1 ] = new String ("Luck" ); s[1 ][0 ] = new String ("to" ); s[1 ][1 ] = new String ("you" ); s[1 ][2 ] = new String ("!" ); public class TestArray { public static void main (String[] args) { int size = 10 ; double [] myList = new double [size]; myList[0 ] = 5.6 ; myList[1 ] = 4.5 ; myList[2 ] = 3.3 ; myList[3 ] = 13.2 ; myList[4 ] = 4.0 ; myList[5 ] = 34.33 ; myList[6 ] = 34.0 ; myList[7 ] = 45.45 ; myList[8 ] = 99.993 ; myList[9 ] = 11123 ; double total = 0 ; for (int i = 0 ; i < size; i++) { total += myList[i]; } System.out.println("总和为: " + total); } }
Java时间
Java正则表达式
Java方法
方法包含于类或对象中
System.out.println()
这句话的用法是调用系统类 System 中的标准输出对象 out 中的方法 println()。
Java IO
创建 BufferedReader 对象的基本语法
1 2 3 4 5 6 import java.io.*;BufferedReader br = new BufferedReader (new InputStreamReader (System.in))public static void main (String[] args) throws IOException {}
常用方法
1 2 3 4 5 6 (char ) br.read() br.readLine() str.equals("end" )
创建 InputStream 对象的基本语法
1 2 3 import java.io.*;InputStream f = new FileInputStream ("C:/java/hello" );public static void main (String[] args) throws IOException {}
常用方法
1 2 3 4 5 6 7 8 f.close(); f.finalize(); f.read(int r) f.read(byte [] r)
创建 OutputStream 对象的基本语法
1 2 3 import java.io.*;OutputStream f = new FileOutputStream ("C:/java/hello" );public static void main (String[] args) throws IOException {}
常用方法
1 2 3 4 5 6 7 8 f.close(); f.write(int w); f.write(byte [] w); f.finalize();
Java Scanner 类
创建 Scanner 对象的基本语法
1 2 3 4 import java.util.Scanner; Scanner scan = new Scanner (System.in);
常用方法
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 System.out.print("xxx" /char ); System.out.println("xxx" /char +....元素); scan.next() scan.hasNext() scan.close(); scan.hasNextLine() scan.nextLine() scan.nextInt() scan.hasNextInt() scan.hasNextFloat() scan.nextFloat()
小程序段
1 2 3 4 5 6 7 public static void nPrintln (String message, int n) { for (int i = 0 ; i < n; i++) { System.out.println(message); } }