hi
i have wrote this progaram in java.
it finf the palidrome numbers and print it.
its by threads
it has some errors and i can t run it.
please help me.
package palindromen;
import java.lang.Integer;
import java.lang.String;
public class Main {
public Main() {
}
public static void main(String[] args)
{int nop,anyt;
Keyboard key=new Keyboard();
System.out.println("Enter number of processors : ");
nop=key.readInt();
anyt=20000/nop;
T Threads[]=new T[nop];
Palindromeset p=new Palindromeset();
for(int i=1;i<=nop;i++) {
Threads=new T("Threads"+Integer.toString(i));
Threads.setr((i*anyt),anyt*(i+1),p);
}
for(int i=1;i<=nop;i++)
Threads.start();
for(int i=1;i<=nop;i++)
try{
Threads.join();
}
catch(Exception e)
{ }
p.print();
}
}
-------------------------------------
package palindromen;
public class Palindromeset extends Thread{
private int buffer[];
private int count;
/** Creates a new instance of Palindromeset */
public Palindromeset() {
count=0;
buffer=new int[20000];
}
public synchronized void addNum(int x)
{buffer[count]=x;
count++;
}
public void print(){
for(int i=0;i<count;i++)
{ System.out.println(buffer);
System.out.println(" ");
}
System.out.println();
System.out.println(count);
}
}
-------------------------------------------------
package palindromen;
public class T extends Thread{
public int lowr,highr,n;
volatile Palindromeset c;
public void setr(int lr,int hr,Palindromeset pt)
{
lowr=lr;
highr=hr;
c=pt;}
public T(String s) {
this.setName(s);
}
public void run()
{for(int i=lowr;i<highr;i++){
n = i; //used at last time check
int reverse=0,remainder;
while(i > 0){
remainder = i % 10;
reverse = reverse * 10 + remainder;
i = i / 10; }
if(reverse == n)
c.addNum(i);
}
}
}