netx_iit

Thread print single digits of number

May 31st, 2021
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.69 KB | None | 0 0
  1. class p3 extends Thread
  2. {
  3.     static String str_no;
  4.     static public void set_no(String n)
  5.     {
  6.         str_no=n;
  7.     }
  8.     public void run()
  9.     {
  10.         char ch[]=str_no.toCharArray();//convert string to char array
  11.         for(int i=0;i<str_no.length();i++)
  12.         {
  13.             try
  14.             {
  15.                 Thread.sleep(1000);
  16.             }
  17.             catch(Exception ex)
  18.             {
  19.                 System.out.println(ex);
  20.             }
  21.             System.out.println(ch[i]);
  22.         }
  23.     }
  24.    
  25.     public static void main(String args[])
  26.     {
  27.         p3 p=new p3();
  28.         if(args.length==0)
  29.         {
  30.             System.out.println("Please enter argument");
  31.         }
  32.         else if(args.length > 1)
  33.         {
  34.             System.out.println("Enter only 1 argument and its number type");
  35.         }
  36.         else
  37.         {
  38.             p3.set_no(args[0]);
  39.             p.start();
  40.         }
  41.     }
  42. }
  43.  
Advertisement
Add Comment
Please, Sign In to add comment