1. 程式人生 > 其它 >故障樹FTA求最小割集

故障樹FTA求最小割集

常用類


Object


getClass:可以用於判斷兩個例項物件是不是同一個類的例項化產物。

public static void main(String[] args) {
Student xh = new Student("xh", 20);
Student xz = new Student("xz", 22);

//使用getClass方法來判斷兩個例項是否是同一個類
Class<? extends Student> xhClass = xh.getClass();
Class<? extends Student> xzClass = xz.getClass
();


if (xhClass==xzClass){
System.out.println("他兩是同一個類");
}

hashcode


該方法返回物件的雜湊值。

雜湊值是根據物件的地址或者字串或者數字使用hash演算法計算出來的int型別的數值。

一般情況下相同物件返回相同的雜湊碼。

toString


返回該物件的字串表示(表現形式)。

可以根據程式需求覆蓋該方法,如:展示物件各個屬性值。

equals


預設實現為(this==obj),比較兩個物件地址是否相同。

可進行覆蓋,比較兩個物件的內容是否相同。

String常用方法


length:返回字串的長度。

charAt:根據下標獲取字元。

contains:判斷當前字串中是否包含某個字串。

toCharArray:將字串換成陣列。

indexOf:查詢str首次出現的下標,存在,返回該下標,不存在返回-1.

lastIndexOf:查詢字串在當前字串中最後一次出現的位置的下標索引。

trim:去掉字串前後的空格。

toUpperCase:將小寫轉成大寫。

endWith:判斷字串是否以str結尾。

replace:對舊字串進行替換成新字串。

split:根據str做拆分。

StringBuffer


該方法和python列表類似,可以通過append方法向字串中加字元。

還有insert的方法可以在指定位置插入資料。

replace,指定位置範圍進行替換資料。

delete,刪除指定位置的資料。

BigDecimal


在精度要求非常高的時候可以進行精確儲存而進行使用。

System


arraycopy:複製陣列。

//arraycopy:陣列的複製
//src:源陣列
//srcPos:從哪個位置開始複製,下標位置
//dest:目標陣列
//destPos:目標陣列的位置,複製結束的位置。
//length:複製的長度
System.arraycopy(src,srcPos,dest,destPos,length);

currentTimeMillis:獲取當前系統時間,返回的是毫秒值。

gc:建議JVM趕快啟動垃圾回收器回收垃圾。

exit:退出JVM,如果引數是0表示正常退出JVM,非0表示異常退出JVM。

package object;

import java.util.Arrays;
import java.util.Calendar;

public class TestStudent {
public static void main(String[] args) {
Student xh = new Student("xh", 20);
Student xz = new Student("xz", 22);

//使用getClass方法來判斷兩個例項是否是同一個類
Class<? extends Student> xhClass = xh.getClass();
Class<? extends Student> xzClass = xz.getClass();

if (xhClass==xzClass){
System.out.println("他兩是同一個類");
}

//hashCode方法
System.out.println(xh.hashCode());
System.out.println(xz.hashCode());

//toString
System.out.println(xh.toString());

//equals
System.out.println(xh.equals(xz));

//自動裝箱和拆箱
int age=30;
//裝箱
Integer integer=age;
//拆箱
int age2=integer;

//字串轉基本型別
String str="150";
//使用Integer.parsexxx;
int n2=Integer.parseInt(str);
System.out.println(n2);

//布林型別字串形式轉成基本型別:“true”-----》true,非“true”——————》false
String str2="true";
boolean b1=Boolean.parseBoolean(str2);
System.out.println(b1);

String name="123";
name="zs";
String name2="zs";
System.out.println(name.hashCode()==name2.hashCode());


String content="java是世界上最好的語言。";
System.out.println(content.length());
System.out.println(content.charAt(3));
System.out.println(content.contains("世界"));

System.out.println(Arrays.toString(content.toCharArray()));
System.out.println(content.indexOf("a"));
System.out.println(content.lastIndexOf("a"));

System.out.println(content.toUpperCase());

System.out.println(content.replace("好","good"));

Calendar ca = Calendar.getInstance();
System.out.println(ca.getTimeInMillis());

System.out.println(ca.get(Calendar.YEAR));

// //arraycopy:陣列的複製
// //src:源陣列
// //srcPos:從哪個位置開始複製,下標位置
// //dest:目標陣列
// //destPos:目標陣列的位置,複製結束的位置。
// //length:複製的長度
// System.arraycopy(src, srcPos, dest, destPos, length);
}
}

# 常用類
---
### Object
---
getClass:可以用於判斷兩個例項物件是不是同一個類的例項化產物。
```javapublic static void main(String[] args) { Student xh = new Student("xh", 20); Student xz = new Student("xz", 22);
//使用getClass方法來判斷兩個例項是否是同一個類 Class<? extends Student> xhClass = xh.getClass(); Class<? extends Student> xzClass = xz.getClass();
if (xhClass==xzClass){ System.out.println("他兩是同一個類"); }```


### hashcode
---
該方法返回物件的雜湊值。
雜湊值是根據物件的地址或者字串或者數字使用hash演算法計算出來的int型別的數值。
一般情況下相同物件返回相同的雜湊碼。


### toString
---
返回該物件的字串表示(表現形式)。
可以根據程式需求覆蓋該方法,如:展示物件各個屬性值。


### equals
---
預設實現為(this==obj),比較兩個物件地址是否相同。
可進行覆蓋,比較兩個物件的內容是否相同。


## String常用方法
---
length:返回字串的長度。
charAt:根據下標獲取字元。
contains:判斷當前字串中是否包含某個字串。
toCharArray:將字串換成陣列。
indexOf:查詢str首次出現的下標,存在,返回該下標,不存在返回-1.
lastIndexOf:查詢字串在當前字串中最後一次出現的位置的下標索引。
trim:去掉字串前後的空格。
toUpperCase:將小寫轉成大寫。
endWith:判斷字串是否以str結尾。
replace:對舊字串進行替換成新字串。
split:根據str做拆分。




### StringBuffer
---
該方法和python列表類似,可以通過append方法向字串中加字元。
還有insert的方法可以在指定位置插入資料。
replace,指定位置範圍進行替換資料。
delete,刪除指定位置的資料。


### BigDecimal
---
在精度要求非常高的時候可以進行精確儲存而進行使用。


## System
---
arraycopy:複製陣列。
```java//arraycopy:陣列的複製//src:源陣列//srcPos:從哪個位置開始複製,下標位置//dest:目標陣列//destPos:目標陣列的位置,複製結束的位置。//length:複製的長度System.arraycopy(src,srcPos,dest,destPos,length);```
currentTimeMillis:獲取當前系統時間,返回的是毫秒值。
gc:建議JVM趕快啟動垃圾回收器回收垃圾。
exit:退出JVM,如果引數是0表示正常退出JVM,非0表示異常退出JVM。
```javapackage object;
import java.util.Arrays;import java.util.Calendar;
public class TestStudent { public static void main(String[] args) { Student xh = new Student("xh", 20); Student xz = new Student("xz", 22);
//使用getClass方法來判斷兩個例項是否是同一個類 Class<? extends Student> xhClass = xh.getClass(); Class<? extends Student> xzClass = xz.getClass();
if (xhClass==xzClass){ System.out.println("他兩是同一個類"); }
//hashCode方法 System.out.println(xh.hashCode()); System.out.println(xz.hashCode());
//toString System.out.println(xh.toString());
//equals System.out.println(xh.equals(xz));
//自動裝箱和拆箱 int age=30; //裝箱 Integer integer=age; //拆箱 int age2=integer;
//字串轉基本型別 String str="150"; //使用Integer.parsexxx; int n2=Integer.parseInt(str); System.out.println(n2);
//布林型別字串形式轉成基本型別:“true”-----》true,非“true”——————》false String str2="true"; boolean b1=Boolean.parseBoolean(str2); System.out.println(b1);
String name="123"; name="zs"; String name2="zs"; System.out.println(name.hashCode()==name2.hashCode());

String content="java是世界上最好的語言。"; System.out.println(content.length()); System.out.println(content.charAt(3)); System.out.println(content.contains("世界"));
System.out.println(Arrays.toString(content.toCharArray())); System.out.println(content.indexOf("a")); System.out.println(content.lastIndexOf("a"));
System.out.println(content.toUpperCase());
System.out.println(content.replace("好","good"));
Calendar ca = Calendar.getInstance(); System.out.println(ca.getTimeInMillis());
System.out.println(ca.get(Calendar.YEAR));
// //arraycopy:陣列的複製// //src:源陣列// //srcPos:從哪個位置開始複製,下標位置// //dest:目標陣列// //destPos:目標陣列的位置,複製結束的位置。// //length:複製的長度// System.arraycopy(src, srcPos, dest, destPos, length); }}```