簡體   English   中英

java中“我無法解決的問題”的任何解決方案?

[英]Any solution to the "i cannot be resolved problem" in java?

我在 java 中有一個用於 DFA 模擬的代碼,我在下面的循環中收到此錯誤,說“我無法解析為變量”。 我不知道它有什么問題,任何人都可以幫助我解決這個問題嗎? 我嘗試了關於日食的固定建議,但會顯示另一個錯誤。

import java.util.Scanner;

public class DFA {

    public static void main(String[] args) {
        
        Scanner sc;
        sc = new Scanner (System.in);
        
        int states;
        System.out.println("Input Number of States: ");
        states = sc.nextInt();
        System.out.println("Input Number of Transition States: ");
        int tStates = sc.nextInt();
        
        int q [][] = new int [states] [tStates];
        System.out.println("Input the Transition Table");
        for (int i = 0; i < states; i++) {
            System.out.println("State " +(i));
            for(int j = 0; j < tStates; j++ ) {
                q[i][j] = sc.nextInt();
            }
        }
        
        System.out.println("Input the String: ");
        String state1;
        state1 = sc.next();
        String in[] = state1.split("");
        System.out.println("Transition Table ");
        System.out.println("         0  1");
        for (int i = 0; i < states; i++) {
            System.out.println("State " + (i) + " ");
            for(int j = 0; j < tStates; j++ ) {
                System.out.println("q" + q[i][j] + " ");
            }
            System.out.println("");
        }
        //input
        int input [] = new int [in.length];
        //splitting with space
        
        for (int i = 0; i <= in.length; i++); {
            if (in[i].equals("a")) {
                input[i] = 0;
            }
            if (in[i].equals("b")) {
                input[i] = 1; 
                }
            }
    
        System.out.println("_________________________");
        int initial = 0;
        int fin = (states - 1);
        int current = initial;
        int ip, nextstate;
        for (int i = 0; i < in.length; i++) {
        System.out.println("q" + current + "--" + input[i] + "-->");
        ip = input[1];
        nextstate = q[current][ip];
        current = nextstate;
            if (i == (in.length - 1)) {
            System.out.println("q" + current);
            }
        }
            if (current == fin) {
            System.out.println("\nAccepted");
            } else {
                System.out.println("\nRejected");

            }
        }
    }

這行就在 if 語句有問題之后。 括號中的 i 是犯錯誤的人。

for (int i = 0; i <= in.length; i++); {
            if (in[i].equals("a")) {
                input[i] = 0;
            }
            if (in[i].equals("b")) {
                input[i] = 1; 
                }
            }

它是for語句右括號后的分號:for語句只包含一個空語句。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM