Showing posts with label ref: https://codesjava.com/synchronized-method-in-java. Show all posts
Showing posts with label ref: https://codesjava.com/synchronized-method-in-java. Show all posts

Thursday, April 30, 2020

Artificial Intelligence Lab

1Write a prolog program to calculate the sum of two numbers.LINK
2Write a prolog program to find the maximum of two numbers.LINK
3Write a prolog program to calculate the factorial of a given number.LINK
4Write a prolog program to calculate the nth Fibonacci number.LINK
5Write a prolog program, insert_nth(item, n, into_list, result) that asserts that result is the list into_list with item inserted as the n‘th element into every list at all levels.LINK
6Write a Prolog program to remove the Nth item from a list.LINK
7Write a Prolog program, remove-nth(Before, After) that asserts the After list is the Before list with the removal of every n‘th item from every list at all levels.LINK
8Write a Prolog program to implement append for two lists.LINK
9 Write a Prolog program to implement palindrome (List).LINK
10Write a Prolog program to implement max(X,Y,Max) so that Max is the greater of two numbers X and Y.LINK
11Write a Prolog program to implement maxlist(List,Max) so that Max is the greatest number in the list of numbers List.LINK
12Write a Prolog program to implement sumlist(List,Sum) so that Sum is the sum of a given list of numbers List.LINK
13Write a Prolog program to implement two predicates evenlength(List) and oddlength(List) so that they are true if their argument is a list of even or odd length respectively.LINK
14 Write a Prolog program to implement reverse(List,ReversedList) that reverses lists.LINK
15Write a Prolog program to implement maxlist(List,Max) so that Max is the greatest number in the list of numbers List using cut predicate.LINK
16Write a Prolog program to implement GCD of two numbers.LINK
17 Write a prolog program that implements Semantic Networks/Frame Structures.

Tuesday, May 7, 2019

synchronization




class PrintTable{ 
//synchronized method.
    public synchronized void printTable(int n){
       System.out.println("Table of " + n);
       for(int i=1;i<=10;i++){
           System.out.println(n*i);
           try{
        Thread.sleep(500);
           }catch(Exception e){
        System.out.println(e);
           }
        }     
    }
}

class MyThread1 extends Thread{
    PrintTable pt;
    MyThread1(PrintTable pt){
    this.pt=pt;
    }
    public void run(){
    pt.printTable(2);
    }     
}

class MyThread2 extends Thread{
PrintTable pt;
MyThread2(PrintTable pt){
this.pt=pt;
}
public void run(){
pt.printTable(5);
}
}

public class p1{
    public static void main(String args[]){
    //creating PrintTable object.
    PrintTable obj = new PrintTable();

    //creating threads.
    MyThread1 t1=new MyThread1(obj);
    MyThread2 t2=new MyThread2(obj);

    //start threads.
    t1.start();
    t2.start();
    }
}



C:\Users\Com science\Documents>java p1
Table of 2
2
4
6
8
10
12
14
16
18
20
Table of 5
5
10
15
20
25
30
35
40
45
50

C:\Users\Com science\Documents>