Tuesday, May 11, 2021

Adv. Java Slip 4 Solution

Slip 4

 /*Write a java program to display “Hello Java” message n times on the screen. (Use Runnable Interface).   */

import java.io.*;

class Hellojava implements Runnable

{

     Thread t;

     public Hellojava(String title)

       {

         t=new Thread(this,title);

         t.start();

       }

       public void run()

        {

          for(int i=0;i<20;i++)

         {

          System.out.println((i+1)+"ThreadName:"+Thread.currentThread().getName());

          try

            {

              Thread.sleep(10000);

            }

  catch(Exception e)

         {

             }

           }

         }

            }

  

 public class Demotext

   {

     public static void main(String args[])

       {

        System.out.println("ThreadName  :  "  +Thread.currentThread().getName());

        Hellojava t1=new Hellojava("HELLO JAVA");

      }

    }

/* Output*/
D:\JavaP>javac Demotext.java

D:\JavaP>java Demotext
ThreadName  :  main
1ThreadName:HELLO JAVA
2ThreadName:HELLO JAVA
3ThreadName:HELLO JAVA
4ThreadName:HELLO JAVA
5ThreadName:HELLO JAVA
6ThreadName:HELLO JAVA
7ThreadName:HELLO JAVA
8ThreadName:HELLO JAVA
9ThreadName:HELLO JAVA
10ThreadName:HELLO JAVA
11ThreadName:HELLO JAVA
12ThreadName:HELLO JAVA
13ThreadName:HELLO JAVA
14ThreadName:HELLO JAVA
15ThreadName:HELLO JAVA
16ThreadName:HELLO JAVA
17ThreadName:HELLO JAVA
18ThreadName:HELLO JAVA
19ThreadName:HELLO JAVA
20ThreadName:HELLO JAVA

No comments:

Post a Comment

Slip 10. Write a jQuery code to make first word of each statement to bold.

  Slip 10. Write a jQuery code to make first word of each statement to bold.  <!DOCTYPE html> <html>   <head>     <scri...