Write a java program to display addition program and subtraction program with 2 sec time gap

Write a java program to display addition program and subtraction program with 2 sec time gap

Program
import java.util.*;
class A
{
    int x,y,z;
    A()
    {
        Scanner s=new Scanner(System.in);
        System.out.println("Enter x,y Values : ");
        x=s.nextInt();
        y=s.nextInt();
    }
}
class ThDemo extends A implements Runnable
{
    void add()
    {
        z=x+y;
        System.out.println("Addition is : "+z);
    }
    void sub()
    {
        z=x-y;
        System.out.println("Subtraction is : "+z);
    }
    public void run()
    {
        try
        {
            add();
            Thread.sleep(2000);
            sub();
        }
        catch(Exception e)
        {
            System.out.println(e);
        } 
    }
}
public class Main
{
    public static void main(String args[])
    {
        ThDemo d=new ThDemo();
        Thread t=new Thread(d);
        t.start();
    }
}


Output:

Enter x,y Values : 12 12
Addition is : 24
Subtraction is : 0


Multi Threading In Java



More Questions


214 . Write a Java-program to Count the number of special characters in a given string ?
215 . Write a Java-program to Count the number of letters in a given string ?
216 . Write a Java-program to Count the number of Numbers in a given string ?
217 . Write a Java-program to Remove vowels in a given string ?
218 . Write a Java-program to Remove consonants in a given string ?
219 . Write a Java-program to Remove special characters in a given string ?
220 . Write a Java-program to Remove spaces in a given string ?
221 . Write a Java-program to Remove letters in a given string ?
222 . Write a Java-program to Remove numbers in a given string ?
223 . Write a Java-program to print duplicate characters from the string ?
224 . Write a Java-program to print unique(distinct (or non-repeating characters) ) characters from the string ?