code
package com.codegym.task.task16.task1626;
import java.util.*;
/*
Requirements:
1. The CountUpRunnable class must implement the Runnable interface.
2. The CountUpRunnable class must have a public run method with no parameters.
3. The CountUpRunnable class's run method should run for approximately 2.5 seconds.
4. Every half second, the CountUpRunnable class's run method should display the thread's name,
a colon, and the value of the counter from 1 to 5 (for example: "Increase: 1").
5. The CountUpRunnable class's run method should call Thread.sleep(500).
*/
public class Solution {
public static int number = 5;
public static void main(String[] args) {
//new Thread(new CountdownRunnable(), "Decrease").start();
Thread t1 = new Thread(new CountUpRunnable(), "Increase");
t1.start();
if(t1.isAlive()){
try{
Thread.sleep(2500);
t1.join();
}catch(Exception ex){
}
}else{
System.out.println(t1.getName()+" has ended..");
}
}
public static class CountUpRunnable implements Runnable{
//write your code here
private int counter = 1;
public void run(){
while(true){
if(counter > 5){
try{
Thread.sleep(500);
}catch(Exception ex){
}
break;
}else{
System.out.println(Thread.currentThread().getName() + ": " + counter++);
/* try{
Thread.sleep(500);
}catch(Exception ex){
}*/
}
}
}
}
}