Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7684533
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T19:02:52+00:00 2026-05-31T19:02:52+00:00

I am coding for a program whose detail is: 1. User enter the value

  • 0

I am coding for a program whose detail is:
1. User enter the value in array and in program automatically entered value times 0 should be inserted in each index.
2. Use threads, first thread calls it decrement(2) in the user entered value and then it goes to sleep for 1 second.
As sleep calls then second thread calls it put a increment of 1 and then sleep goes for 2 seconds then again first thread call it again decrement in the incremented value and so on until the value of decremented thread equals to zero.
As value of decrement equal to zero then incrementing automatically must stop.

I have the code now help me if any one has understand my question…

All comments should be appreciated..

       //Through Implementing Runnable Interface

      //Create a second thread

      //import java.util.Scanner;




 class NewThread extends Thread implements Runnable {
Thread t;
NewThread(){
//Create a new, second thread

t = new Thread(this, "Demo AASSINGMENT");
//System.out.println("Child Thread: "+ t);
t.start();//Start the thread

}

 //This is the entry point for the second thread.


 public void run(){

   try{
for(int i = 10; i>0; --i){

System.out.println("Decrement: " +i);
//i--;
//System.out.println("Child Thread 2nd dec: " + i);
Thread.sleep(1000);
}
   }


catch(InterruptedException e){
System.out.println("Decrement INterrupted");
}   

System.out.println("Oops!! -- Decreasing Value is less than or equal to zero");
 }//run

 }//class



 class ThreadDemo {


public static void main(String args[]){
new NewThread();//create a new thread
 int[] arr; int dj;

//   Scanner input = new Scanner(System.in);
  //  System.out.print("Enter Your Desired Value : ");
    //int z = input.nextInt();
    try{

     //arr = new int[z];
    //for(dj =0; dj<array.length;dj++)
    //{
      //  array[dj]=0;
       // System.out.println("0's inserted "+ array[dj]);
    //}

                //while(z!=0){

    for(int i = 10; i<=14; i++){

    System.out.println("Increment: " +i);
    //if(i>6){
    //System.out.println("Main Thread Exiting");}
    Thread.sleep(2000);

                  }//for

   }//try

catch(InterruptedException e){
System.out.println("Main Thread Interrupted");
}   
System.out.println("Increasing Value has exceeded from 14 so  Exiting");


    }//main
    }//class
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T19:02:53+00:00Added an answer on May 31, 2026 at 7:02 pm

    In your main method, you create an instance of newThread, but you never start it. Unless you start it, it will never execute.

    Edit to provide more implementation info

    As a precursor to the following explanation, normally you don’t have your classes extend Thread. Instead, implement Runnable then create a standard Thread instance that executes your Runnable instance.

    So, I would suggest that you modify the code as follows:

    class NewRunnable implements Runnable
    {
        public void run()
        {
            // Do important background stuff here
        }
    }
    
    public static void main (String[] args)
    {
        Thread thr = new Thread ( new NewRunnable( ) ) ;
        thr.start( ) ;
    
        // Do other important stuff
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm coding a little program that has to sort a large array (up to
I am coding a program where a form opens for a certain period of
I'm coding a windows program which is a WYSIWYG form generator. In a very
I am currently coding some chat program and now want to play music via
I almost done my coding for a specific program i have. I just need
I wrote my first program almost fifty years ago (yes, coding is still a
I am coding for a pthread C++ program. I got error: pthread_getunique_np was not
So I am coding this client/server program. This code is from the client side.
I was recently coding a small java program (as design for an 8086 Assembler
I am coding an internet cafe program and trying to decide which path to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.