? asked in 電腦與網際網路程式設計 · 1 decade ago

這是用java寫的程式要怎麼用VB寫出來阿!請幫幫我!拜託!

因為我不太會用VB!!可是現在這個程式的內容必須用VB寫出來!!不知道有沒有精通VB跟java的高手可以幫幫我.拜託!

public class OmegaMin_1{

public static void main(String arg[]){

int f1, f2, f3, f4, cnt, omegaCnt, i, j;

int[][] x;

int[][] omega;

//

// 找出所有符合條件的"f",並列出 F (f1, f2, f3, f4)

//

System.out.println("\nThe result of\"F\"is");

cnt=0;

for(f1=0; f1>=0 && f1<=6; f1++){

for(f2=0; f2>=0 && f2<=6; f2++){

for(f3=0; f3>=0 && f3<=6; f3++){

for(f4=0; f4>=0 && f4<=6; f4++){

if(f1+f2+f3+f4==5 && f1+f2+f3+f4<=6 && f1+f2+f4<=5 && f2+f3+f4<=6){

cnt++;

System.out.print("("+f1+", "+f2+", "+f3+", "+f4+") ");

}

}

}

}

}

System.out.println("\nTotal ="+cnt);

System.out.println("-----------------------------------------------------------------------------");

//

// 將對應的"f"帶入式子,求出所有的"x",並列出 X (x1, x2, x3, x4)

//

System.out.println("The result of \"X \" is");

x=new int[cnt][4];

i=0;

for(f1=0; f1>=0 && f1<=6; f1++){

for(f2=0; f2>=0 && f2<=6; f2++){

for(f3=0; f3>=0 && f3<=6; f3++){

for(f4=0; f4>=0 && f4<=6; f4++){

if(f1+f2+f3+f4==5 && f1+f2+f3+f4<=6 && f1+f2+f4<=5 && f2+f3+f4<=6){

x[i][0]=f1+f2+f3+f4;

x[i][1]=f1+f2+f4;

x[i][2]=f2+f3+f4;

x[i][3]=f1+f2+f3+f4;

System.out.print("("+x[i][0]+ ", "+x[i][1]+ ", "+x[i][2]+ ", "+x[i][3]+ ") ");

i++;

}

}

}

}

}

System.out.println("\n");

//

// 所列出的 X (x1, x2, x3, x4),將相同的過濾掉,找出 Omega

//

System.out.println("The result of\"Omega \"is");

for(i=0; i<cnt; i++){

for(j=i+1; j<cnt; j++){

if(x[i][0]==x[j][0] && x[i][1]==x[j][1] && x[i][2]==x[j][2] && x[i][3]==x[j][3]){

x[j][0]=0;

x[j][1]=0;

x[j][2]=0;

x[j][3]=0;

}

}

}

j=0;

for(i=0;<cnt; i++){

if(x[i][0]==0&&x[i][1]==0&&x[i][2]==0&&x[i][3]==0){

j++;

}

}

omegaCnt=cnt-j;

Update:

omega= new int[omegaCnt][4];

j=0;

for(i=0; i<cnt; i++){

if(x[i][0]==0&& x[i][1]==0 && x[i][2]==0 && x[i][3]==0){

} else{

omega[j][0]=x[i][0];

omega[j][1]=x[i][1];

omega[j][2]=x[i][2];

omega[j][3]=x[i][3];

System.out.print("("+omega[j][0]+ ", "+omega[j][1]+ ", "+omega[j][2]+ ", "+omega[j][3]+ ") ");

j++;

}

}

Update 2:

System.out.print("("+omega[j][0]+ ", "+omega[j][1]+ ", "+omega[j][2]+ ", "+omega[j][3]+ ") ");

j++;

}

}

System.out.println("\nTotal= "+omegaCnt);

System.out.println("-----------------------------------------------------------------------------");

//

// 找出最小的 X (x1, x2, x3, x4),即為 Omega minimal

//

Update 3:

System.out.println("The result of \"Omega minimal\" is");

for(i=0; i<omegaCnt; i++){

for(j=i+1; j<omegaCnt; j++){

if(omega[i][0]==0 && omega[i][1]==0 && omega[i][2]==0 &&omega[i][3]==0){

} else if(omega[j][0]==0 && omega[j][1]==0 && omega[j][2]==0 && omega[j][3]==0){

} else{

Update 4:

if(omega[i][0] <omega[j][0] || omega[i][1] <omega[j][1] || omega[i][2] <omega[j][2] || omega[i][3] <omega[j][3]){

if(omega[i][0] >omega[j][0] || omega[i][1] >omega[j][1] || omega[i][2] >omega[j][2] || omega[i][3] >omega[j][3]){

} else{

omega[j][0]=0;

omega[j][1]=0;

omega[j][2]=0;

omega[j][3]=0;

}

} else{

Update 5:

omega[i][0]=0;

omega[i][1]=0;

omega[i][2]=0;

omega[i][3]=0;

}

}

}

}

for(i=0; i<omegaCnt; i++){

if(omega[i][0]==0 && omega[i][1]==0 && omega[i][2]==0 && omega[i][3]==0){

} else{

System.out.print("("+omega[i][0]+ ", "+omega[i][1]+ ", "+omega[i][2]+ ", "+omega[i][3]+ ") ");

}

}

System.out.println("\n");

}

}

2 Answers

Rating
  • Cola
    Lv 5
    1 decade ago
    Best Answer

    以下是用vb6寫的

    Sub main()

    Dim f1 As Integer

    Dim f2 As Integer

    Dim f3 As Integer

    Dim f4 As Integer

    Dim cnt As Integer

    '找出所有符合條件的”f”,並列出 F (f1, f2, f3, f4)

    Debug.Print "The result of ""F"" is"

    For f1 = 0 To 6

    For f2 = 0 To 6

    For f3 = 0 To 6

    For f4 = 0 To 6

    If f1 + f2 + f3 + f4 = 5 And f1 + f2 + f3 + f4 <= 6 And f1 + f2 + f4 <= 5 And f2 + f3 + f4 <= 6 Then

    cnt = cnt + 1

    Debug.Print "(" + Str(f1) + ", " + Str(f2) + ", " + Str(f3) + ", " + Str(f4) + ") "

    End If

    Next

    Next

    Next

    Next

    Debug.Print "Total =" + Str(cnt)

    Debug.Print "-----------------------------------------------------------------------------"

    '將對應的"f"帶入式子,求出所有的"x",並列出 X (x1, x2, x3, x4)

    Debug.Print "The result of "" X "" is"

    Dim i As Integer

    Dim x() As Integer

    ReDim x(cnt - 1, 3)

    i = 0

    For f1 = 0 To 6

    For f2 = 0 To 6

    For f3 = 0 To 6

    For f4 = 0 To 6

    If f1 + f2 + f3 + f4 = 5 And f1 + f2 + f3 + f4 <= 6 And f1 + f2 + f4 <= 5 And f2 + f3 + f4 <= 6 Then

    x(i, 0) = f1 + f2 + f3 + f4

    x(i, 1) = f1 + f2 + f4

    x(i, 2) = f2 + f3 + f4

    x(i, 3) = f1 + f2 + f3 + f4

    Debug.Print "(" + Str(x(i, 0)) + ", " + Str(x(i, 1)) + ", " + Str(x(i, 2)) + ", " + Str(x(i, 3)) + ") "

    i = i + 1

    End If

    Next

    Next

    Next

    Next

    2009-12-02 19:58:43 補充:

    '所列出的 X (x1, x2, x3, x4),將相同的過濾掉,找出 Omega

    Debug.Print "The result of ""Omega"" is"

    Dim j As Integer

    For i = 0 To cnt - 1

    For j = i + 1 To cnt - 1

    2009-12-02 19:58:59 補充:

    If x(i, 0) = x(j, 0) And x(i, 1) = x(j, 1) And x(i, 2) = x(j, 2) And x(i, 3) = x(j, 3) Then

    x(j, 0) = 0

    x(j, 1) = 0

    x(j, 2) = 0

    x(j, 3) = 0

    End If

    Next

    Next

    2009-12-02 19:59:13 補充:

    j = 0

    For i = 0 To cnt - 1

    If x(i, 0) = 0 And x(i, 1) = 0 And x(i, 2) = 0 And x(i, 3) = 0 Then

    j = j + 1

    End If

    Next

    2009-12-02 19:59:46 補充:

    Dim omegaCnt As Integer

    omegaCnt = cnt - j

    Dim omega() As Integer

    ReDim omega(omegaCnt - 1, 3)

    2009-12-02 20:00:09 補充:

    j = 0

    For i = 0 To cnt - 1

    If x(i, 0) = 0 And x(i, 1) = 0 And x(i, 2) = 0 And x(i, 3) = 0 Then

    Else

    omega(j, 0) = x(i, 0)

    omega(j, 1) = x(i, 1)

    omega(j, 2) = x(i, 2)

    omega(j, 3) = x(i, 3)

    2009-12-02 20:00:14 補充:

    Debug.Print "(" + Str(omega(j, 0)) + ", " + Str(omega(j, 1)) + ", " + Str(omega(j, 2)) + ", " + Str(omega(j, 3)) + ") "

    j = j + 1

    End If

    Next

    2009-12-02 20:00:46 補充:

    Debug.Print "Total= " + Str(omegaCnt)

    Debug.Print "-----------------------------------------------------------------------------"

    2009-12-02 20:02:01 補充:

    '找出最小的 X (x1, x2, x3, x4),即為 Omega minimal

    Debug.Print "The result of ""Omega minimal"" is"

    For i = 0 To omegaCnt - 1

    For j = i + 1 To omegaCnt - 1

    If omega(i, 0) = 0 And omega(i, 1) = 0 And omega(i, 2) = 0 And omega(i, 3) = 0 Then

    2009-12-02 20:02:50 補充:

    ElseIf omega(j, 0) = 0 And omega(j, 1) = 0 And omega(j, 2) = 0 And omega(j, 3) = 0 Then

    Else

    If omega(i, 0) < omega(j, 0) Or omega(i, 1) < omega(j, 1) Or omega(i, 2) < omega(j, 2) Or omega(i, 3) < omega(j, 3) Then

    2009-12-02 20:03:35 補充:

    If omega(i, 0) > omega(j, 0) Or omega(i, 1) > omega(j, 1) Or omega(i, 2) > omega(j, 2) Or omega(i, 3) > omega(j, 3) Then

    2009-12-02 20:04:34 補充:

    Else

    omega(j, 0) = 0

    omega(j, 1) = 0

    omega(j, 2) = 0

    omega(j, 3) = 0

    End If

    2009-12-02 20:04:40 補充:

    Else

    omega(i, 0) = 0

    omega(i, 1) = 0

    omega(i, 2) = 0

    omega(i, 3) = 0

    End If

    End If

    Next

    Next

    2009-12-02 20:05:00 補充:

    For i = 0 To omegaCnt - 1

    If omega(i, 0) = 0 And omega(i, 1) = 0 And omega(i, 2) = 0 And omega(i, 3) = 0 Then

    Else

    2009-12-02 20:05:09 補充:

    Debug.Print "(" + Str(omega(i, 0)) + ", " + Str(omega(i, 1)) + ", " + Str(omega(i, 2)) + ", " + Str(omega(i, 3)) + ") "

    End If

    Next

    End Sub

    2009-12-02 20:05:30 補充:

    若是vb2005則建立Console應用程式

    程式碼修改

    Dim x() As Integer

    ReDim x(cnt - 1, 3)

    以上兩行改Dim x(cnt - 1, 3) As Integer

    Dim omega() As Integer

    ReDim omega(omegaCnt - 1, 3)

    以上兩行改Dim omega(omegaCnt - 1, 3) As Integer

    Debug.Print改Console.WriteLine

    最後面再補一行Console.ReadKey()

    2009-12-02 20:09:07 補充:

    若有問題請再提問

    2009-12-02 21:46:12 補充:

    不知道是不是字數超過,補充的部份全不見了???

    完整的程式碼請版大到下面免空下載

    http://www.mediafire.com/?edj4gnjtwzm

    若有問題請再提問

  • Anonymous
    6 years ago

    我每次都是去這里看的哦, http://Lvmiss。com

    偺刕品偑勽二

Still have questions? Get your answers by asking now.