Tuesday, 29 November 2016

Program to input a string and print each character from that separately on screen with a delay of 100ms after each character

This program will print each character from a given string with a delay of 100ms.


PROGRAM
import java.util.Scanner;

public class PrintCharWithDelay {

 public static void main(String[] args) {

  Scanner s = new Scanner(System.in);
  System.out.print("Enter the string :: ");
  String str = s.nextLine();
  
  for(int i=0; i<str.length(); i++) {
   System.out.println(str.charAt(i));
   try {
    Thread.sleep(100);
   } 
   catch (InterruptedException e) {
    e.printStackTrace();
   }
  }
 }

}
OUTPUT
C:\>javac PrintCharWithDelay.java
C:\>java PrintCharWithDelay
Enter the string :: Rahul
R
a
h
u
l

No comments:

Post a Comment