Java 8.9

Java switch 语句


public class Mine {
	static <T> void pln(T x){
		System.out.println(x);
	}
	static void Out(char grade) {
		switch(grade) {
		case 'A':
			pln("Execellent");
			break;
		case 'B':
			pln("Good");
			break;
		case 'C':
			pln("Well");
			break;
		case 'D':
			pln("Qualified");
			break;
		}
		pln("Your academic level is: " + grade);
	}
	public static void main(String[] args) {
		char grade = 'C';
		Out(grade);
	}
}

可修改的stringbuffer类


public class Mine {
	static <T> void pln(T x) {
		System.out.println(x);
	}
	public static void main(String[] args) {
		StringBuffer string = new StringBuffer();
		string.append("KasakiNozomi");
		pln(string);
		string.append(" YoroizukaMozore");
		pln(string);
	}
}

Java数组


public class Mine {
	static void pnln(double[] List) {
		for(int i = 0; i < List.length; i++) {
			System.out.print(List[i]);
			System.out.print(' ');
			for(double x : List) {
			System.out.print(x);
			System.out.print(' ');
		}
		}
	}
	public static void main(String[] args) {
		double[] List = new double[10];
		double list[] = new double[10];
		for(int i = 0 ; i < List.length; i++) {
			List[i] = Math.random();
			list[i] = Math.random();
		}
		pnln(List);
		System.out.println('\n');
		pnln(list);
	}
}

Java时间操作

import java.text.SimpleDateFormat;
import java.util.Date;

public class Mine{
	static <T> void pln(T x) {
		System.out.println(x);
	}
	public static void main(String[] args) {
		Date date = new Date();
		pln(date.toString());
		SimpleDateFormat ftDateFormat = new SimpleDateFormat("yyyy年MM月dd日  a hh:mm:ss");
		pln("当前时间为:" + ftDateFormat.format(date));
	}
}

可变个数参数


public class Mine{
	static <T> void pln(T x) {
		System.out.println(x);
	}
	static void Pmax(double... number) {
		if(number.length == 0) {
			pln("No number...");
			return;
		}
		double m_ax = number[0];
		for(int i = 1; i < number.length; i++) {
			m_ax = Math.max(m_ax, number[i]);
		}
		pln("The max is : " + m_ax);
	}
	public static void main(String[] args) {
		Pmax(1,2,3,34,5,6);
		Pmax(new double[] {2,3,3});
	}

}
posted @ 2023-08-09 11:54  N0zoM1z0  阅读(0)  评论(0编辑  收藏  举报