二刷java核心技術_重溫基礎部分的練習程式碼儲存

Pop_Rain發表於2017-06-21

這段程式碼沒啥用,就是一些小的語法知識點,看一遍能喚醒記憶

import static java.lang.Math.*;
import java.math.*;
import java.io.*;
import java.util.*;
import java.nio.file.Path;
import java.nio.file.*;
//enum Size(big, small);

public class HelloWorld
{
	public static final double D = 32.4321;
	
	public static long jie(long start,long end)
	{
		if(start != end)
			return start * jie(start+1, end);
		return end; 
	}
	
	public static void main(String args[]) throws IOException
	{
//		Console cons = System.console();
//		String name = cons.readLine(null, args);
//		System.out.println(name);
//		char pwd[] = cons.readPassword("password: ");
//		System.out.println(pwd);
		
//		Scanner inData = new Scanner(System.in);
//		Double age = inData.nextDouble();
//		System.out.println(age);
		
		System.out.println(1.0/3);
//		System.out.printf("hello %s, you are %+,(.5f\n", "cby", -22312324.1235123);
//		System.out.printf("hello %s\n%s\n", "wqe", -224.35123);
		
//		String form = String.format("hello %s, you are %+,(.5f\n", "cby", -22312324.1235123);
//		System.out.println(form);
//		System.out.printf("%tF\n", new Date());
//		System.out.printf("%1$s %2$tY %2$tB %2$td\n", "日期:", new Date());
//		System.out.printf("%1$s %2$tY %<tB %<td\n", "日期:", new Date());
		
//		Scanner in = new Scanner(Paths.get("d:\\1.txt"));
//		String data = in.nextLine();
//		System.out.println(data); //從檔案中提取資料資訊並列印輸出
			
//		PrintWriter out = new PrintWriter("d:\\1.txt");
//		out.println("hahahaha");  //寫入資料資訊到指定檔案
//		out.flush(); //重新整理檔案
		
		int a2[] = {5,4,3,2,1};
		
		for(int ele: a2)
			System.out.print(ele + " ");
		System.out.println();
		
		Arrays.sort(a2);
		
		for(int ele: a2)
			System.out.print(ele + " ");
		System.out.println();
		
		for(int i=1; i<=10; i+=2)
		{
			if(i == 1)
				System.out.print(i);
			else
				System.out.print(" " + i);
		}
		System.out.print('\n');
		
		long x = 50;
		long k = 6;
		long res = jie(x-k+1, x)/jie(1,k);
		System.out.println(res);
		
		BigInteger a1 = BigInteger.valueOf(100);
		System.out.println(a1.multiply(BigInteger.valueOf(900)));
		
		int data1[] = {1,2,34,5};
		int data2[] = data1;
		int data3[] = Arrays.copyOf(data1, 4);
		System.out.println(data3[2]);
		
		int a43[][] = new int[4][];
		for(int i=0; i<a43.length; ++i)
			a43[i] = new int[i+1];
		for(int i=0; i<a43.length; ++i)
			for(int j=0; j<a43[i].length; ++j)
				a43[i][j] = j;
		System.out.println(Arrays.deepToString(a43));
		
		System.out.println();
		
		int n1 = 2;
		haha:
		switch(n1)
		{
			case 1:
				System.out.println("1 bingo!");
				break;
			case 2:
				System.out.println("2 bingo!");
				break haha;
			case 5:
				System.out.println("5 bingo!");
				break;
			default:
				System.out.println("bonggogog!");
				break;
		}
		
		
		
		boolean x9 = false;
		if(!x9)
		{
			int n = 0b1000; //n==8
			int result = (n & (1<<3))>>3; 
			//System.out.println(Math.pow(PI, 1));
		}
		
		//Size size = Size.small;
		//System.out.println(size);
		
		int sa = 1123214_32;
		int sb = 2;
		sb += sa+=1; //從右往左的優先順序
		//System.out.println(sa);
		
		//System.out.println("java\u2122");
		String ss = new String();  //String不是java資料型別,是一個預定義類
		ss = "HelloWorld";
		String sh = "myfriends";  //可以直接寫
		ss = ss.substring(0,5) + sh;
		int num = 43;
		String haha = "haha" + num;
		//System.out.println(ss + "\n" + sh + num);
		System.out.println(ss);
		
		
		boolean t = true;
		double result = D/0;
		
		String as = "hello\n";
		int len = as.length();
		int realSize = as.codePointCount(0, as.length());
		System.out.println(len);
		System.out.println(realSize);
		
		String bs = "hello ";
		bs = bs.replace("hell", "  cby");
		System.out.println(bs.toUpperCase().trim());
		
		StringBuilder sb1 = new StringBuilder();
		sb1.append("h");
		String sb2 = sb1.toString();
		System.out.println(sb2);
		System.out.println(sb2.length());
		
		if(as!=null && as.length()!=0)
		{
			System.out.println("haha1");
		}
		else
		{
			System.out.println("ahaha1");
		}
//		if(as.compareTo("hel") == 0)
//		{
//			System.out.println("haha2");
//		}
//		else
//		{
//			System.out.println("ahaha2");
//		}
		
		System.out.println("haha " + D*2 + " by " + D*(3+2));
		if(Double.isNaN(result) == false)
		{
			System.out.println("result.isnotNaN");
		}
	}
}

相關文章