Java simulation automatic Typing effect code

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.