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

Popular posts from this blog

Program to define a class 'employee' with data members as empid, name and salary. Accept data for 5 objects using Array of objects and print it.

Define a class Student with four data members such as name, roll no.,sub1, and sub2. Define appropriate methods to initialize and display the values of data members. Also calculate total marks and percentage scored by student.

Program to input age from user and throw user-defined exception if entered age is negative