Skip to content

Instantly share code, notes, and snippets.

@antonengelhardt
Created January 29, 2023 20:44
Show Gist options
  • Save antonengelhardt/11878b21c40cae2d19ea6e56546b04ac to your computer and use it in GitHub Desktop.
Save antonengelhardt/11878b21c40cae2d19ea6e56546b04ac to your computer and use it in GitHub Desktop.
from time import sleep
def main():
word = ['H', 'e', 'l', 'l', 'o', ' ', 'W', 'o', 'r', 'l', 'd', '!']
alphabet = [' ', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '!']
current_word = ''
for i in range(len(word)):
for j in range(len(alphabet)):
print(current_word + alphabet[j])
sleep(0.05)
if word[i] == alphabet[j] or word[i] == alphabet[j].upper():
current_word = current_word + alphabet[j]
break
if __name__ == '__main__':
main()
@Izhaan-Raza
Copy link

how can i do this in java

@antonengelhardt
Copy link
Author

antonengelhardt commented Feb 11, 2023

@Izhaan-Raza Sure.

public class HelloWorld {

    public static void main(String[] args) {
        char[] word = {'H', 'e', 'l', 'l', 'o', ' ', 'W', 'o', 'r', 'l', 'd', '!'};
        char[] alphabet = {' ', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '!'};

        String currentWord = "";

        for (int i = 0; i < word.length; i++) {
            for (int j = 0; j < alphabet.length; j++) {
                System.out.println(currentWord + alphabet[j]);
                
                try {
                    Thread.sleep(20);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                if (word[i] == alphabet[j] || word[i] == alphabet[j] - 32) {
                    currentWord += alphabet[j];
                    break;
                }
            }
        }
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment