1) WAP To Demostrate Making of Thread To Print Numbers From 1 To 10
1) WAP To Demostrate Making of Thread To Print Numbers From 1 To 10
1) WAP To Demostrate Making of Thread To Print Numbers From 1 To 10
class Main
{
public static void main(String[] args) {
firstten f1 = new firstten();
Thread t1 = new Thread(f1);
t1.start();
}
}
2) WAP that has two threads. One of the threads displays odd numbers and other displays
even numbers.
import java.util.Scanner;
/**
* Created by akshay on 11/10/2016.
*/
class Odd extends Thread
{
public void run()
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter a number");
int n=sc.nextInt();
for (int i=1; i<=n; i++)
{
if(i%2!=0)
{ System.out.println(i); }
}
}
}
class demoMain
{
public static void main(String args[])
{
Odd t1=new Odd();
Even t2= new Even();
t1.start();
t2.start();
}
}
4) WAP that has two threads. One of the threads displays fibonacci series and the other
displays prime numbers upto n.
import java.util.Scanner;
/**
* Created by akshay on 11/10/2016.
*/
public class fibo extends Thread {
int a=0,b=1,c;
public void run()
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter x for fibonacci");
int x = sc.nextInt();
System.out.println(a);
System.out.println(b);
for(int i=1;i<=x-2;i++)
{
c=a+b;
System.out.println(c);
a=b;
b=c;
}
}
}
class Maine
{
public static void main(String[]args){
}
}
char ch='a';
public void run() {
for (int i = 0; i <= 26; i++)
{
System.out.println(ch++);
}
}
}
class Mainee
{
public static void main(String[] args) {
abcd a1 = new abcd();
numb n1 = new numb();
a1.start();
n1.start();
}
}
char ch = 'a';
class Maineee
{
public static void main(String[] args) {
ajeeb a1 = new ajeeb();
nimbu n1 = new nimbu();
a1.start();
n1.start();
}
}
/**
* Created by akshay on 11/10/2016.
*/
public class sleep {
int i;
for(i=0;i<=10;i++)
{
System.out.println(i);
Thread.sleep(4000);
}