導航:首頁 > 源碼編譯 > java入侵檢測源碼

java入侵檢測源碼

發布時間:2023-08-09 18:42:20

java 源代碼 基礎點的 謝謝

package com.regex;
import java.io.*;
import java.net.URLDecoder;
import java.util.regex.*;
public class Regex {
private int REMARK=0;
private int LOGIC=0;
private int PHYSIC=0;
boolean start=false;

/**
* @param args
*/
public static void main(String[] args) { //測試方法
// TODO Auto-generated method stub
Regex re=new Regex();
re.regCount("Regex.java");
System.out.println("remark Line: "+re.REMARK);
System.out.println("logic Line: "+re.LOGIC);
System.out.println("physic Line: "+re.PHYSIC);

}/**
* @author BlueDance
* @param s
* @deprecated count
*/
public void regCount(String s){
String url=null;
try {
url=URLDecoder.decode(this.getClass().getResource(s).getPath(),"UTF-8");
} catch (Exception e) {
e.printStackTrace();
// TODO: handle exception
}
try {
BufferedReader br=new BufferedReader(new FileReader(new File(url)));
String s1=null;
while((s1=br.readLine())!=null){
PHYSIC++;
if(CheckChar(s1)==1){
REMARK++;
System.out.println("純注釋行:"+s1);
}
if(CheckChar(s1)==2){
LOGIC++;
REMARK++;
System.out.println("非純注釋行:"+s1);
}
if(CheckChar(s1)==3)
LOGIC++;
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}catch(IOException e){
e.printStackTrace();
}

}
/**
*
* @param s
* @return int
* @version check s
*/
public int CheckChar(String s){
String s1=null;
if(s!=null)
s1=s.trim();

//System.out.println(regCheck(s1,re));
if(regCheck(s1,"(//.*)")) //判斷//開頭的為純注釋行
return 1;
if(regCheck(s1,"(.*[;{})] *//.*)")) //判斷不是//開頭的非純注釋行
return 2;
if(regCheck(s1,"(//*.*)")){ //判斷/*開頭的純注釋行
start=true;
return 1;
}
if(regCheck(s1,"(.*[;{})]//*.*)")){ //判斷不是/*開頭的非純注釋行
start=true;
return 2;
}
if(regCheck(s1,"(.* */*/)")){ //判斷*/結尾的純注釋行
start=false;
return 1;
}
if(regCheck(s1,"(.* */*/.*)")&&!strCheck(s1)){ //判斷不是*/結尾的非純注釋行
if(strCheck(s1)){
start=false;
return 2;
}
}
if(start==true) //狀態代碼,start即/*開始時start=true*/結束時為false
return 1;
return 3;//ssssllll
}//aeee
/**
*
* @param s
* @param re
* @return boolean
*/
public boolean regCheck(String s,String re){ //正則表達試判斷方法
return Pattern.matches(re,s);
}
public boolean strCheck(String s){ //中間有*/的字元判斷 此方法最關鍵
if(s.indexOf("*/")>0){
int count=0;
String y[]=s.split("/*/");
boolean boo[]=new boolean[y.length];
for (int i = 0; i < y.length-1; i++) {
char c[]=y[i].toCharArray();
for (int j = 0; j < c.length; j++) {
if(c[j]=='\\'&&c[j+1]=='"'){
count++;
}
}
if(count%2==0){
if(countNumber("\"",y[i])%2!=0){
boo[i]=true;
}else{
boo[i]=false;
}
}else{
if(countNumber("\"",y[i])%2==0){
boo[i]=true;
}else{
boo[i]=false;
}
}

}
for(int i=0;i<boo.length;i++){
if(!boo[i])
return false;
}
return true;
}
return false;
}
public int countNumber(String s,String y){ //此方法為我前面寫的字元串出現次數統計方法,不懂的可以看我前面的文章
int count=0;
String [] k=y.split(s);
if(y.lastIndexOf(s)==(y.length()-s.length()))
count=k.length;
else
count=k.length-1;
if(count==0)
System.out.println ("字元串\""+s+"\"在字元串\""+y+"\"沒有出現過");
else
return count;
return -1;
}

}

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class GoodLucky extends JFrame implements ActionListener{

JTextField tf = new JTextField(); //實例化一個文本域
//設置兩個按鈕
JButton b1 = new JButton("開始");
JButton b2 = new JButton("停止");
boolean isGo = false;
//構造函數
public GoodLucky(){
b1.setActionCommand("start");//在開始按鈕上設置一個動作監聽 start
JPanel p = new JPanel(); //實例化一個可視化容器
//將兩個按鈕添加到可視化容器上面,用add方法
p.add(b1);
p.add(b2);
//在兩個按鈕上增加監聽的屬性,自動調用下面的監聽處理方法actionPerformed(ActionEvent e),如果要代碼有更好的可讀性,可用內部類實現動作
//監聽處理。
b1.addActionListener(this);
b2.addActionListener(this);
//將停止按鈕設置為不可編輯(即不可按的狀態)
b2.setEnabled(false);

this.getContentPane().add(tf,"North"); //將上面的文本域放在面板的北方,也就是上面(上北下南左西右東)
this.getContentPane().add(p,"South"); //將可視化容器pannel放在南邊,也就是下面
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //設置用戶在此窗體上發起 "close" 時默認執行的操作,參數EXIT_ON_CLOSE是使用 System exit 方法退出應用程序。僅在應用程序中使用

this.setSize(300,200); //設置面板大小,寬和高
this.setLocation(300,300); //設置面板剛開始的出現的位置
Cursor cu = new Cursor(Cursor.HAND_CURSOR); //用指定名稱創建一個新的定製游標對象,參數表示手狀游標類型
this.setCursor(cu); //為指定的游標設置游標圖像,即設置游標圖像為上面所創建的手狀游標類型
this.setVisible(true); //將面板可視化設置為true,即可視,如果為false,即程序運行時面板會隱藏
tf.setText("welcome you! "); //設置面板的標題為歡迎
this.go(); //調用go方法

}

public void go(){
while(true){ //這里是死循環,也就是說用戶不點擊停止按鈕的話他一直循環出現隨機數,直到用戶點擊停止按鈕循環才能推出,具體流程在actionPerformed方法中控制。
if(isGo == true){ //上面所定義的isGo的初始值為false,所以程序第一次到此會跳過
String s = ""; //設置空字元串
for(int j = 1; j <= 7;j++){ //產生7個隨機數
int i = (int)(Math.random() * 36) + 1;//每個隨機數產生方式,這里定義靈活,可以自由定義隨機數產生的方式
if(i < 10){
s = s + " 0" + i; //如果產生的隨機數小於10的話做處理:這里就牽扯到一個重要的概念,簡單敘述一下:
/*
當一個字元串與一個整型數項相加的意思是連接,上面的s = s + " 0" + i的意思是字元串s鏈接0再連接整型i值,而不會導致0和整型的i相加,
產生的效果為s0i,由於s為空字元串(上面定義過的),所以當i小於零時,在個位數前面加上0,比如產生的隨機數i為7的話,顯示效果為 07.
*/
}else{
s = s + " " + i; //如果產生的隨機數比10打的話,那麼加上空格顯示,即數字和數字之間有個空格
}
//以上循環循環七次,以保證能出現7個隨機數
}
tf.setText(s); //將產生的隨機數全部顯示在文本域上,用文本域對象tf調用它的設置文本的方法setText(String)實現。
}

//以下為線程延遲
try{
Thread.sleep(10); //線程類同步方法sleep,睡眠方法,括弧里的單位為ms。
}catch(java.lang.InterruptedException e){
e.printStackTrace(); //異常捕獲,不用多說。
}

}

}

//以下是上面設置的事件監聽的具體處理辦法,即監聽時間處理方法,自動調用
public void actionPerformed(ActionEvent e){ //傳入一個動作事件的參數e
String s = e.getActionCommand(); //設置字元串s來存儲獲得動作監聽,上面的start
/*
以下這個條件語句塊的作用為:用戶點擊開始後(捕獲start,用方法getActionCommand()),將命令觸發設置為true,從而執行上面的go方法中的循環體(因為循環體中要求isGo參數為true,而初始為false)。
執行循環快產生隨機數,並將開始按鈕不可編輯化,而用戶只可以使用停止按鈕去停止。如果用戶按下停止時,也就是沒有傳入參數「start」的時候,
執行else語句塊中的語句,isGo設置為false,將不執行上面go中的循環語句塊,從而停止產生隨機數,並顯示,並且把開始按鈕設置為可用,而把
停止按鈕設置為不可用,等待用戶按下開始再去開始新一輪循環產生隨機數。
*/
if(s.equals("start")){ //如果捕獲到start,也就是用戶觸發了動作監聽器,那麼下面處理
isGo = true; //設置isGo為true
b1.setEnabled(false); //將開始按鈕設置為不可用
b2.setEnabled(true); //將停止按鈕設置為可用
}else{
isGo = false; //將isGo設置為false,isGo為循環標志位
b2.setEnabled(false); //設置停止按鈕為不可用(注意看是b2,b2是停止按鈕)
b1.setEnabled(true); //設置開始按鈕為可用
}

}

public static void main(String[] args){
new GoodLucky(); //產生類的實例,執行方法
}
}

❷ java新手,求完整的源代碼

//都是從新手過來的,以下代碼供參考
//1.
publicclassBankAccount{
privatestaticStringacctnum;
privatestaticdoublemoney;

privatestaticvoidshowAcct(){
System.out.println("賬號為:"+acctnum);
}

privatestaticvoidshowMoney(){
System.out.println("余額為:"+money);
}

publicBankAccount(Stringacc,doublem){
this.acctnum=acc;
this.money=m;
}

publicstaticvoidmain(String[]args){
BankAccountba=newBankAccount("626600018888",5000.00);
ba.showAcct();
ba.showMoney();

}

}

//2.

publicclassTriangle{
privatestaticfloata;
privatestaticfloatb;
privatestaticfloatc;

publicTriangle(floata,floatb,floatc){
this.a=a;
this.b=b;
this.c=c;
}

(floata,floatb,floatc){
if((a>Math.abs(b-c)&&a<b+c)
&&(b>Math.abs(a-c)&&b<a+c)
&&(c>Math.abs(a-b)&&c<a+b))
returntrue;
else
returnfalse;
}

publicfloatgetCircumference(){
returnthis.a+this.b+this.c;
}
}

//3.

publicclassTestTriangle{


publicstaticvoidmain(String[]args){
Trianglet=newTriangle(5.3f,7.8f,9.3f);

if(t.judgeTriangle(5.3f,7.8f,9.3f)){
System.out.print("能夠成三角形,周長為:");
System.out.printf("%9.2f",t.getCircumference());}
else
System.out.println("不能構成三角形");
}

}

❸ 高分求兩個簡單的JAVA設計源代碼

上面 wukun12同學寫的不錯,但我想還不能運行,並且還不太完善。我給個能運行的:(注意:文件名為:Test.java)

//要實現對象間的比較,就必須實現Comparable介面,它裡面有個compareTo方法
//Comparable最好使用泛型,這樣,無論是速度還是代碼量都會減少
@SuppressWarnings("unchecked")
class Student implements Comparable<Student>{

private String studentNo; //學號
private String studentName; //姓名
private double englishScore; //英語成績
private double computerScore; //計算機成績
private double mathScore; //數學成績
private double totalScore; //總成績

//空構造函數
public Student() {}

//構造函數
public Student(String studentNo,String studentName,double englishSocre,double computerScore,double mathScore) {
this.studentNo = studentNo;
this.studentName = studentName;
this.englishScore = englishSocre;
this.computerScore = computerScore;
this.mathScore = mathScore;
}

//計算總成績
public double sum() {

this.totalScore = englishScore+computerScore+mathScore;
return totalScore;
}

//計算評測成績
public double testScore() {

return sum()/3;
}

//實現compareTO方法
@Override
public int compareTo(Student student) {
double studentTotal = student.getTotalScore();
return totalScore==studentTotal?0:(totalScore>studentTotal?1:-1);
}

//重寫toString方法
public String toString(){
return "學號:"+this.getStudentNo()+" 姓名:"+this.getStudentName()+" 英語成績:"+this.getEnglishScore()+" 數學成績:"+this.getMathScore()+" 計算機成績:"+this.getComputerScore()+" 總成績:"+this.getTotalScore();
}

//重寫equals方法
public boolean equals(Object obj) {
if(obj == null){
return false;
}
if(!(obj instanceof Student)){
return false;
}
Student student = (Student)obj;
if(this.studentNo.equals(student.getStudentName())) { //照現實來說,比較是不是同一個學生,應該只是看他的學號是不是相同
return true;
} else {
return false;
}

}

/*以下為get和set方法,我個人認為,totalScore的set的方法沒必要要,因為它是由其它成績計算出來的
在set方法中,沒設置一次值,調用一次sum方法,即重新計算總成績
*/
public String getStudentNo() {
return studentNo;
}
public void setStudentNo(String studentNo) {
this.studentNo = studentNo;
sum();
}
public String getStudentName() {
return studentName;
}
public void setStudentName(String studentName) {
this.studentName = studentName;
sum();
}
public double getEnglishScore() {
return englishScore;
}
public void setEnglishScore(double englishScore) {
this.englishScore = englishScore;
sum();
}
public double getComputerScore() {
return computerScore;
}
public void setComputerScore(double computerScore) {
this.computerScore = computerScore;
sum();
}
public double getMathScore() {
return mathScore;
}
public void setMathScore(double mathScore) {
this.mathScore = mathScore;
sum();
}
public double getTotalScore() {
return totalScore;
}

}

//Student子類學習委員類的實現
class StudentXW extends Student {

//重寫父類Student的testScore()方法
@Override
public double testScore() {
return sum()/3+3;
}

public StudentXW() {}

//StudentXW的構造函數
public StudentXW(String studentNo,String studentName,double englishSocre,double computerScore,double mathScore) {
super(studentNo,studentName,englishSocre,computerScore,mathScore);
}
}

//Student子類班長類的實現
class StudentBZ extends Student {

//重寫父類Student的testScore()方法
@Override
public double testScore() {
return sum()/3+5;
}

public StudentBZ() {}

//StudentXW的構造函數
public StudentBZ(String studentNo,String studentName,double englishSocre,double computerScore,double mathScore) {
super(studentNo,studentName,englishSocre,computerScore,mathScore);
}
}

//測試類
public class Test {

public static void main(String[] args) {

//生成若干個student類、StudentXW類、StudentBZ類
Student student1 = new Student("s001","張三",70.5,50,88.5);
Student student2 = new Student("s002","李四",88,65,88.5);
Student student3 = new Student("s003","王五",67,77,90);
StudentXW student4 = new StudentXW("s004","李六",99,88,99.5);
StudentBZ student5 = new StudentBZ("s005","朱漆",56,65.6,43.5);

Student[] students = {student1,student2,student3,student4,student5};

for(int i = 0 ; i<students.length; i++){
double avgScore = students[i].testScore();
System.out.println(students[i].getStudentName()+"學生的評測成績為:"+ avgScore+"分");
}

}
}
運行結果為:
張三學生的評測成績為:69.66666666666667分
李四學生的評測成績為:80.5分
王五學生的評測成績為:78.0分
李六學生的評測成績為:98.5分
朱漆學生的評測成績為:60.03333333333333分

閱讀全文

與java入侵檢測源碼相關的資料

熱點內容
常用cmd網路命令 瀏覽:676
hashmap7源碼分析 瀏覽:896
搜索引擎原理技術與系統pdf 瀏覽:359
運動估計演算法python 瀏覽:858
java正則1 瀏覽:536
redhatlinux最新 瀏覽:177
python字典編程詞彙 瀏覽:144
微信和伺服器如何通訊 瀏覽:10
百家號伺服器配置有什麼用 瀏覽:598
怎麼為電腦加密 瀏覽:58
伺服器出現差錯是什麼意思 瀏覽:616
蘋果app移到商店裡怎麼刪掉 瀏覽:254
phpjsphtml 瀏覽:63
吃雞手機國際服伺服器超時怎麼辦 瀏覽:68
努比亞Z5無命令 瀏覽:642
展示網站雲伺服器 瀏覽:872
代碼混淆器php 瀏覽:367
貝恩pdf 瀏覽:209
丙烯pdf 瀏覽:368
雲伺服器華碩 瀏覽:713