Notes
![]() ![]() Notes - notes.io |
private int[][] transitionTable;
private int currentState;
private int[] acceptingStates;
public DFSA() {
transitionTable = new int[9][3];
transitionTable[0][0] = 1;
transitionTable[0][1] = -1;
transitionTable[0][2] = -1;
transitionTable[1][0] = 2;
transitionTable[1][1] = 3;
transitionTable[1][2] = -1;
transitionTable[2][0] = 4;
transitionTable[2][1] = 5;
transitionTable[2][2] = -1;
transitionTable[3][0] = -1;
transitionTable[3][1] = -1;
transitionTable[3][2] = 6;
transitionTable[4][0] = -1;
transitionTable[4][1] = 5;
transitionTable[4][2] = -1;
transitionTable[5][0] = -1;
transitionTable[5][1] = -1;
transitionTable[5][2] = 6;
transitionTable[6][0] = -1;
transitionTable[6][1] = -1;
transitionTable[6][2] = -1;
transitionTable[7][0] = 4;
transitionTable[7][1] = 5;
transitionTable[7][2] = -1;
transitionTable[8][0] = -1;
transitionTable[8][1] = -1;
transitionTable[8][2] = 6;
currentState = 0;
acceptingStates = new int[]{1, 3, 6, 2, 5, 6};
}
public boolean process(String input) {
currentState = 0; // Reset to initial state
for (char symbol : input.toCharArray()) {
int symbolIndex = getSymbolIndex(symbol);
if (symbolIndex == -1) {
return false;
}
currentState = transitionTable[currentState][symbolIndex];
if (currentState == -1) {
return false;
}
}
for (int state : acceptingStates) {
if (currentState == state) {
return true;
}
}
return false;
}
private int getSymbolIndex(char symbol) {
switch (symbol) {
case 'a':
return 0;
case '0':
return 1;
case '1':
return 2;
default:
return -1;
}
}
public static void main(String[] args) {
DFSA dfsa = new DFSA();
String[] testStrings = {"a", "a0", "a01", "aa", "aa0", "aa01"};
for (String testString : testStrings) {
boolean result = dfsa.process(testString);
if (result) {
System.out.println("The string "" + testString + "" is accepted by the DFSA.");
} else {
System.out.println("The string "" + testString + "" is not accepted by the DFSA.");
}
}
}
}
![]() |
Notes is a web-based application for online taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000+ notes created and continuing...
With notes.io;
- * You can take a note from anywhere and any device with internet connection.
- * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
- * You can quickly share your contents without website, blog and e-mail.
- * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
- * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.
Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.
Easy: Notes.io doesn’t require installation. Just write and share note!
Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )
Free: Notes.io works for 14 years and has been free since the day it was started.
You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;
Email: [email protected]
Twitter: http://twitter.com/notesio
Instagram: http://instagram.com/notes.io
Facebook: http://facebook.com/notesio
Regards;
Notes.io Team