Ideas:
1: Turn the string into an array of strings, use for the sequence to print the array subscript, with the thread of sleep to delay.
2: Use the Charat () method in string, and then with the for loop to print the character at the specified index, using sleep to delay.
1 Public classautomatictyping {2 3 Public Static voidMain (string[] args) {4ATy ATy =NewATy ();//Create an Object5Thread T =NewThread (Aty);//Create a thread6T.start ();//Thread Start7 8 }9 Ten } One classATyImplementsrunnable{ AString Wenben = "An idle youth, boss knocks code \ n-----by h4ckso1di3r"; - - Public voidrun () { the for(inti=0; I<wenben.length (); i++){ - System.out.print (Wenben.charat (i)); - Try { -Thread.Sleep (200); +}Catch(interruptedexception e) { - e.printstacktrace (); + } A } at //another way to do this is to convert the string to a string array and print it sequentially . - //Char [] a =wenben.tochararray (); - //for (int i = 0;i<a.length;i++) { - //System.out.print (A[i]); - //try { - //Thread.Sleep ($); in //} catch (Interruptedexception e) { - // //TODO auto-generated Catch block to //e.printstacktrace (); + // } - // } the } *}
Java simulation automatic Typing effect code