java隨筆——java API
阿新 • • 發佈:2018-11-09
//String類 public class Main { public static void main(String[] args) { String str1=new String(); String str2=new String("abcd"); char[] charArray=new char[] {'D','E','F'}; String str3=new String(charArray); System.out.println(str2); System.out.println(charArray); System.out.println(str3); } }
public class Main { public static void main(String[] args) { String str="abcd"; char[] charArray=str.toCharArray();//把字串轉化為字元陣列 for(int i=0;i<str.length();i++) { System.out.print(charArray[i]); } System.out.println(); System.out.println(String.valueOf(12));//把一個整形化為支付串 System.out.println(str.toUpperCase());//把字串變成大寫 String str1="abck"; System.out.println(str1.replace("a","A")); System.out.println(str1.equals(str)); } }
//Math類
public class Main
{
public static void main(String[] args)
{
System.out.println(Math.abs(-1));//絕對值
System.out.println(Math.ceil(5.1));//去小數
System.out.println(Math.floor(5.9));//有小數進一
System.out.println(Math.round(4.6));//四捨五入
System.out.println(Math.random());//隨機取值
}
}