Download 1 - Radhe Polara

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
Name:-Radhe Polara
Class:-SYBCA(4th Sem)
Roll no:-135
Div:-c
Sub:-Java programming Language
1). WAP to accept names from the user and print within following form:
I/p:-Arvind S Patel
o/p:-A.S.Patel
import java.io.*;
import java.util.*;
class Stringmanip
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
String str;
System.out.println("enter string:-");
str=sc.nextLine();
System.out.println("original string="+ str);
String str1;
int pos=str.indexOf(" ");
int po=str.indexOf(" ",pos+1);
str1=str.substring(po+1);
System.out.println(str.charAt(0) + "." +str.charAt(pos+1) +"." +str1);
}
}
Output:D:\java>javac Stringmanip.java
D:\java>java Stringmanip
enter string:Hardika Babubhai Faldu
original string=Hardika Babubhai Faldu
H.B.Faldu
Name:-Radhe Polara
Class:-SYBCA(4th Sem)
Roll no:-135
Div:-c
Sub:-Java programming Language
2). WAP that executes three threads from one thread class. One thread displays
“java” for every 1 second and second displays ‘c’ for every 2 seconds, third
thread displays “c++” every 3 seconds.
class A extends Thread
{
public void run()
{
try
{
sleep(1000);
System.out.println("java");
}
catch(Exception e)
{
}
}
}
class B extends Thread
{
public void run()
{
try
{
sleep(2000);
System.out.println("C");
}
catch(Exception e)
{
}
}
}
class C extends Thread
{
public void run()
{
try
{
sleep(3000);
System.out.println("C++");
Name:-Radhe Polara
Class:-SYBCA(4th Sem)
Roll no:-135
Div:-c
Sub:-Java programming Language
}
catch(Exception e)
{
}
}
}
class ThreadTest
{
public static void main(String args[])
{
A obj1=new A();
obj1.start();
B obj2=new B();
obj2.start();
C obj3=new C();
obj3.start();
}
}
Output:D:\java>javac ThreadTest.java
D:\java>java ThreadTest
java
C
C++
Name:-Radhe Polara
Class:-SYBCA(4th Sem)
Roll no:-135
Div:-c
Sub:-Java programming Language
3). Write a program to pass the number through command line argument and
check whether inputted number is floating number or not.
import java.io.*;
class floating
{
public static void main(String args[])throws IOException
{
int z=0;
String tem[]=new String[5];
try
{
int i=args.length;
for(int j=0;j<i;j++)
{
tem[j]=args[j].toString();
int l=tem[j].length();
for(int k=0;k<l;k++)
{
if(tem[j].charAt(k) == '.')
throw new RuntimeException("ERROR");
}
}
if(z==0)
{
System.out.println("Floating point not found");
}
}
catch(RuntimeException e)
{
System.out.println("Floating point found");
z++;
}
}
}
Name:-Radhe Polara
Class:-SYBCA(4th Sem)
Roll no:-135
Div:-c
Sub:-Java programming Language
Output:D:\>cd java
D:\java>javac floating.java
D:\java>java floating 1.2 2 8
Floating point found
D:\java>
Name:-Radhe Polara
Class:-SYBCA(4th Sem)
Roll no:-135
Div:-c
Sub:-Java programming Language
4). Write a program that pass command line argument of name different student
arrange them in name wise increasing order.
import java.io.*;
import java.util.*;
class Stringmani
{
public static void main(String args[])
{
int no=args.length;
String name[]=new String[no];
String temp;
for(int i=0;i<args.length;i++)
{
name[i]=args[i];
}
for(int i=0;i<args.length;i++)
{
for(int j=i+1;j<args.length;j++)
{
if(name[j].compareTo(name[i])<0)
{
temp=name[i];
name[i]=name[j];
name[j]=temp;
}
}
}
for(int i=0;i<args.length;i++)
{
System.out.println(name[i]);
}
}
}
Name:-Radhe Polara
Class:-SYBCA(4th Sem)
Roll no:-135
Div:-c
Sub:-Java programming Language
Output:D:\java>javac Stringmani.java
D:\java>java Stringmani Hardika bhumi nirali neha sneha
Hardika
bhumi
neha
nirali
sneha
Name:-Radhe Polara
Class:-SYBCA(4th Sem)
Roll no:-135
Div:-c
Sub:-Java programming Language
5). write a program to pass number though command line argument and cheak
whether inputted number Armstrong or not Armstrong
import java.io.*;
class Armstrong
{
int sum,de,i,n,temp;
Armstrong()
{
sum=0;
}
void setdata(int no)
{
n=no;
}
void calculate()
{
temp=n;
while(n>0)
{
de=n%10;
sum=sum+(de*de*de);
n=n/10;
}
if(temp==sum)
{
System.out.println("number is armstrong");
}
else
{
System.out.println("number is not armstrong");
}
}
}
class ArmTest
{
public static void main(String args[])
{
int no=Integer.parseInt(args[0]);
Armstrong arm=new Armstrong();
Name:-Radhe Polara
Class:-SYBCA(4th Sem)
Roll no:-135
Div:-c
Sub:-Java programming Language
arm.setdata(no);
arm.calculate();
}
}
Output:D:\java>javac ArmTest.java
D:\java>java ArmTest 153
number is armstrong
Name:-Radhe Polara
Class:-SYBCA(4th Sem)
Roll no:-135
Div:-c
Sub:-Java programming Language
6). WAP that create and start three threads each thread is initialize from the
same class it executes a loop with 10 iteration each iteration display the character
A and sleep between 300 to 500 millisecond the application wait for all threads to
complete and then display a message.
Name:-Radhe Polara
Class:-SYBCA(4th Sem)
Roll no:-135
Div:-c
Sub:-Java programming Language
( IMP )
7).WAP to java code which will read a string and rewrite it in alphabetical order.
E.G. computer
O/p:-cemoprtu
import java.io.*;
import java.util.*;
class Stringmanipu
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.print("enter string:-");
String name1;
name1=sc.nextLine();
char temp;
char name[]=name1.toCharArray();
System.out.println(name);
for(int i=0;i<name.length;i++)
{
for(int j=i+1;j<name.length;j++)
{
if(name[j]<name[i])
{
temp=name[i];
name[i]=name[j];
name[j]=temp;
}
}
}
for(int i=0;i<name.length;i++)
{
System.out.print(name[i]);
}
}
}
Name:-Radhe Polara
Class:-SYBCA(4th Sem)
Roll no:-135
Div:-c
Sub:-Java programming Language
Output:D:\java>javac Stringmanipu.java
D:\java>java Stringmanipu
enter string:-computer
computer
cemoprtu
Name:-Radhe Polara
Class:-SYBCA(4th Sem)
Roll no:-135
Div:-c
Sub:-Java programming Language
(8)WAP that generates a custom exception if any inputted value is not in limit -5
to +5.
import java.lang.Exception;
import java.util.*;
class myexception extends Exception
{
myexception(String message)
{
super(message);
}
}
class Limit
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
try
{
System.out.print("enter no:-");
int no=sc.nextInt();
if(no<=-5 || no>=5)
{
throw new myexception("Num is not limit in -5 to 5");
}
}
catch(myexception e)
{
System.out.println(e);
}
}
}
Name:-Radhe Polara
Class:-SYBCA(4th Sem)
Roll no:-135
Div:-c
Sub:-Java programming Language
Output:D:\java>javac Limit.java
D:\java>java Limit
enter no:-2
D:\java>java Limit
enter no:-10
myexception: Num is not limit in -5 to 5
Name:-Radhe Polara
Class:-SYBCA(4th Sem)
Roll no:-135
Div:-c
Sub:-Java programming Language
( IMP )
9)Write a program to accept a string and count total number of uppercase
character and lowercase character in a string.
import java.io.*;
class upp
{
public static void main(String s[]) throws IOException
{
DataInputStream x=new DataInputStream(System.in);
System.out.println("\n Enter the String:");
String n=x.readLine();
int l=n.length();
int i;
int c=0,d=0,e=0,f=0,g=0;
for(i=0;i<l;i++)
{
char r=n.charAt(i);
if(r>=65 && r<=90)
{
c=c+1;
}
else
if(r>=97 && r<=122)
{
d=d+1;
}
else
if(r>=47 && r<=58)
{
e=e+1;
}
else
if(r==32)
{
f=f+1;
}
else
{
g=g+1;
}
}
System.out.println("\n The UPPERCASE character is:"+c);
Name:-Radhe Polara
Class:-SYBCA(4th Sem)
Roll no:-135
Div:-c
Sub:-Java programming Language
System.out.println("\n The LOWERCASE character is:"+d);
System.out.println("\n The DIGIT
is:"+e);
System.out.println("\n The BLANK SPACE
is:"+f);
System.out.println("\n The SPECIAL character is:"+g);
}
}
OUTPUT:-
Enter the String:
java JAVA !@#$ 123
The UPPERCASE character is:4
The LOWERCASE character is:4
The DIGIT
is:3
The BLANK SPACE
is:3
The SPECIAL character is:4
Name:-Radhe Polara
Class:-SYBCA(4th Sem)
Roll no:-135
Div:-c
Sub:-Java programming Language
( IMP )
10). WAP to find all rotation of string given at command line.all condition shiuld
be checked.
Ex. Input: Test
O/p:-Test,estT,stTe,tTes
import java.io.*;
class Test
{
public static void main(String args[])
{
String str=args[0];
for(int i=0;i<str.length();i++)
{
for(int j=i;j<str.length();j++)
{
System.out.print(str.charAt(j));
}
for(int k=0;k<=i-1;k++)
{
System.out.print(str.charAt(k));
}
System.out.println();
}
}
}
Output:D:\java>javac Test.java
D:\java>java Test Test
Test
estT
stTe
tTes
Name:-Radhe Polara
Class:-SYBCA(4th Sem)
Roll no:-135
Div:-c
Sub:-Java programming Language
11). Write a code which accept names depanding on user`s choice stored in to
array and display those names having length greater then 10
Name:-Radhe Polara
Class:-SYBCA(4th Sem)
Roll no:-135
Div:-c
Sub:-Java programming Language
( MIMP)
12). Write a program to accept flower name through parameter in an applet,
print it, also store in html file in the flower directory
import java.awt.*;
import java.applet.*;
public class para extends Applet
{
public void paint(Graphics g)
{
String str=getParameter("font");
String str1=getParameter("string");
int size=Integer.parseInt(getParameter("size"));
g.setFont(new Font(str,Font.BOLD,size));
g.setColor(Color.blue);
g.drawString(str1,200,200);
showStatus("Parameter pass");
}
}
Output:-
D:\>cd java
D:\java>javac para.java
Html Page:<html>
<body>
<applet code="para.class" height="100%" width="100%">
<param name="font" value="Gigi" >
Name:-Radhe Polara
Class:-SYBCA(4th Sem)
Roll no:-135
Div:-c
Sub:-Java programming Language
<param name="size" value="72">
<param name="string" value="..........Rose............">
</applet>
</body>
</html>
Output:-
Name:-Radhe Polara
Class:-SYBCA(4th Sem)
Roll no:-135
Div:-c
Sub:-Java programming Language
(MIMP)
13). Write aapplet to display House
import java.awt.*;
import java.applet.*;
public class House extends Applet
{
public void paint(Graphics g)
{
int n=3;
int x[]=new int[n];
int y[]=new int[n];
x[0]=140;
y[0]=90;
x[1]=70;
y[1]=180;
x[2]=210;
y[2]=180;
g.drawPolygon(x,y,n);
int n1=4;
int x1[]=new int[n1];
int y1[]=new int[n1];
x1[0]=140;
y1[0]=90;
x1[1]=420;
y1[1]=90;
x1[2]=490;
y1[2]=180;
x1[3]=210;
y1[3]=180;
g.drawPolygon(x1,y1,n1);
int n2=4;
int x2[]=new int[n2];
int y2[]=new int[n2];
x2[0]=70;
y2[0]=180;
x2[1]=70;
y2[1]=400;
x2[2]=490;
y2[2]=400;
x2[3]=490;
Name:-Radhe Polara
Class:-SYBCA(4th Sem)
Roll no:-135
Div:-c
Sub:-Java programming Language
y2[3]=180;
g.drawPolygon(x2,y2,n2);
g.drawLine(210,180,210,400);
int n3=4;
int x3[]=new int[n3];
int y3[]=new int[n3];
x3[0]=300;
y3[0]=400;
x3[1]=300;
y3[1]=250;
x3[2]=395;
y3[2]=250;
x3[3]=395;
y3[3]=400;
g.drawPolygon(x3,y3,n3);
g.drawLine(174,90,244,180);
g.drawLine(207,90,277,180);
g.drawLine(241,90,311,180);
g.drawLine(275,90,345,180);
g.drawLine(309,90,379,180);
g.drawLine(343,90,413,180);
g.drawLine(377,90,447,180);
g.drawLine(300,260,395,260);
g.drawLine(100,220,180,220);
g.drawLine(100,300,180,300);
g.drawLine(100,220,100,300);
g.drawLine(180,220,180,300);
g.drawLine(120,220,120,300);
g.drawLine(140,220,140,300);
g.drawLine(160,220,160,300);
g.drawLine(180,220,180,300);
g.drawLine(100,240,180,240);
g.drawLine(100,260,180,260);
g.drawLine(100,280,180,280);
}
}
Name:-Radhe Polara
Class:-SYBCA(4th Sem)
Roll no:-135
Div:-c
Sub:-Java programming Language
Output:-
D:\java>javac House.java
Html code:<html>
<head>
</head>
<body>
<applet code="House.class" height=600 width=600>
</applet>
</body>
</html>
Output:-
Name:-Radhe Polara
Class:-SYBCA(4th Sem)
Roll no:-135
Div:-c
Sub:-Java programming Language
( M I M P)
14). Write a applet to display Human Face
import java.applet.*;
import java.awt.*;
public class Face extends Applet
{
public void paint(Graphics g)
{
g.drawOval(150,150,300,300);
g.drawOval(200,220,30,50);
g.drawOval(205,240,20,30);
g.drawOval(370,220,30,50);
g.drawOval(375,240,20,30);
int n=3;
int x[]=new int[n];
int y[]=new int[n];
x[0]=300;
y[0]=280;
x[1]=250;
y[1]=350;
x[2]=350;
y[2]=350;
g.drawPolygon(x,y,n);
g.drawArc(200,280,200,150,200,135);
}
}
Output:-
D:\java>javac Face.java
D:\java>
Name:-Radhe Polara
Class:-SYBCA(4th Sem)
Roll no:-135
Div:-c
Sub:-Java programming Language
Html Code:-
<html>
<head>
</head>
<body>
<applet code="Face.class" height=100% width=100%>
</applet>
</body>
</html>
Output:-
Name:-Radhe Polara
Class:-SYBCA(4th Sem)
Roll no:-135
Div:-c
Sub:-Java programming Language
( I M P)
15). The class Jetplane declares one Abstract method numEngines(). Therefor,
the class itself must also be declare Abstract. There are at a two concrete
subclasses named DC* and CD10. each of these provides a different
implementation of the numEngines() method. The main() method instantiates
each of these classes and invokes its numEngines() method.
import java.io.*;
abstract class Jetplane
{
abstract void numEngines();
}
class DC extends Jetplane
{
void numEngines()
{
int no1,no2,ans;
no1=50;
no2=10;
ans=no1+no2;
System.out.println("sum=" +ans);
}
}
class CD10 extends Jetplane
{
void numEngines()
{
int no1,no2,ans;
no1=50;
no2=10;
ans=no1*no2;
System.out.println("multiplication=" +ans);
}
}
Name:-Radhe Polara
Class:-SYBCA(4th Sem)
Roll no:-135
Div:-c
Sub:-Java programming Language
class inter
{
public static void main(String args[])
{
DC d1=new DC();
CD10 c1=new CD10();
d1.numEngines();
c1.numEngines();
}
}
Output:-
D:\java>javac inter.java
D:\java>java inter
sum=60
multiplication=500
Name:-Radhe Polara
Class:-SYBCA(4th Sem)
Roll no:-135
Div:-c
Sub:-Java programming Language
IMP
16). WAP that illustrates interface inheritance. Interface P is extends by P1 and
P2. interface P12 inherits from both P1 and P2. each interface declares one
constants and one method. Class Q implements P12. instantiate Q and invoke
each if its method. Each method display one of the constant.
import java.io.*;
interface P
{
final int a=2;
void dispP();
}
interface P1 extends P
{
final int b=5;
void dispP1();
}
interface P2 extends P
{
final int c=10;
void dispP2();
}
interface P12 extends P1,P2
{
final int d=15;
void dispP12();
}
class Q implements P12
{
public void dispP()
{
System.out.println("a:-"+a);
}
public void dispP1()
{
System.out.println("b:-"+b);
}
public void dispP2()
{
System.out.println("c:-"+c);
}
Name:-Radhe Polara
Class:-SYBCA(4th Sem)
Roll no:-135
Div:-c
Sub:-Java programming Language
public void dispP12()
{
System.out.println("d:-"+d);
}
}
class interfaceTest
{
public static void main(String args[])
{
Q q=new Q();
q.dispP();
q.dispP1();
q.dispP2();
q.dispP12();
}
}
Output:D:\java>javac interfaceTest.java
D:\java>java interfaceTest
a:-2
b:-5
c:-10
d:-15
Name:-Radhe Polara
Class:-SYBCA(4th Sem)
Roll no:-135
Div:-c
Sub:-Java programming Language
17). Write a application that illustrates how a method can invoke a super class.
ClassI2 is extended by class J2. class J2 extended by K2. each of these classes
defines a “getdetail()” that return a string. That string includes a description of a
class+description of each super class. Instantiate each of these classes and
invoked the getdetail().
Name:-Radhe Polara
Class:-SYBCA(4th Sem)
Roll no:-135
Div:-c
Sub:-Java programming Language
18). WAP to create Package called “stud” in which create a class “student”
which contain the information rollno and name of students.
Create another package “marks” in which create a class “studmarks”
which is extended from “student” and it contain instance variable say marks of 3
subjects.
Write a java code to store main() in different package and required
argument through command line.
Name:-Radhe Polara
Class:-SYBCA(4th Sem)
Roll no:-135
Div:-c
Sub:-Java programming Language
IMP
19). Write a program to generate Fibonacci series using Recursion
import java.io.*;
class febo
{
int feb(int n)
{
int fe;
if (n==1 || n==0)
{
return 0;
}
else if(n==2)
{
return 1;
}
else
{
return (feb(n-1)+feb(n-2));
}
}
}
class Febonaci
{
public static void main(String args[])
{
int n,i=1;
n=Integer.parseInt(args[0]);
febo f=new febo();
while(i<=n)
{
i++;
System.out.println(f.feb(i));
}
}
}
Name:-Radhe Polara
Class:-SYBCA(4th Sem)
Roll no:-135
Div:-c
Sub:-Java programming Language
Output:-
D:\java>javac Febonaci.java
D:\java>java Febonaci 10
1
1
2
3
5
8
13
21
34
55
D:\java>
Name:-Radhe Polara
Class:-SYBCA(4th Sem)
Roll no:-135
Div:-c
Sub:-Java programming Language
IMP
20). An example of Dead Lock.
class A
{
B b;
synchronized void a1()
{
System.out.println("string a1");
b.b2();
}
synchronized void a2()
{
System.out.println("string a2");
}
}
class B
{
A a;
synchronized void b1()
{
System.out.println("string b1");
a.a2();
}
synchronized void b2()
{
System.out.println("string b2");
}
}
class Th1 extends Thread
{
A a;
Th1(A a)
{
this.a=a;
}
public void run()
{
for(int i=0;i<10;i++)
{
Name:-Radhe Polara
Class:-SYBCA(4th Sem)
Roll no:-135
Div:-c
Sub:-Java programming Language
a.a1();
}
}
}
class Th2 extends Thread
{
B b;
Th2(B b)
{
this.b=b;
}
public void run()
{
for(int i=0;i<10;i++)
{
b.b1();
}
}
}
class Deadlock
{
public static void main(String args[])
{
A a=new A();
B b=new B();
a.b=b; //get lock on a
b.a=a; //get lock on b
Th1 t1=new Th1(a);
Th2 t2=new Th2(b);
t1.start();
t2.start();
try
{
t1.join();
t2.join();
}
Name:-Radhe Polara
Class:-SYBCA(4th Sem)
Roll no:-135
Div:-c
Sub:-Java programming Language
catch(Exception e)
{
e.printStackTrace();
}
System.out.println("done..........");
}
}
Output:-
D:\java>javac Deadlock.java
D:\java>java Deadlock
string a1
string b1
Name:-Radhe Polara
Class:-SYBCA(4th Sem)
Roll no:-135
Div:-c
Sub:-Java programming Language
IMP
21). Write a program to accept a string and print the uppercase to lowercase and
vice versa.
Ex:-i/p:-i am student
o/p:-I AM STUDENT
import java.util.*;
class LowerUpper
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
String str,str1,str2;
System.out.print("enter string:-");
str=sc.nextLine();
str1=str.toLowerCase();
str2=str.toUpperCase();
System.out.println("origional string=" +str);
if(str.equals(str1))
{
System.out.println("converted string=" +str.toUpperCase());
}
else if(str.equals(str2))
{
System.out.println("converted string=" +str.toLowerCase());
}
else
{
System.out.println("converted string=" +str.toUpperCase());
}
}
}
Name:-Radhe Polara
Class:-SYBCA(4th Sem)
Roll no:-135
Div:-c
Sub:-Java programming Language
Output:-
D:\java>javac LowerUpper.java
D:\java>java LowerUpper
enter string:-i am student
origional string=i am student
converted string=I AM STUDENT
D:\java>java LowerUpper
enter string:-I AM STUDENT
origional string=I AM STUDENT
converted string=i am student
D:\java>
Name:-Radhe Polara
Class:-SYBCA(4th Sem)
Roll no:-135
Div:-c
Sub:-Java programming Language
IMP
22). Write a java code to input a line of next and replace all the occurrences of
inputed character by eplacing character
Ex:- coconut
Character to be replace:-c
Replace with:-t
O/p:- totonut
import java.util.*;
class replacechar
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
String str,str1,str2;
System.out.print("enter string:-");
str=sc.nextLine();
System.out.print("enter character you want to replace it:-");
str1=sc.nextLine();
System.out.print("enter character you want to change it:-");
str2=sc.nextLine();
System.out.println("origional string=" +str);
str=str.replace(str1,str2);
System.out.println("Replace string:-" +str);
}
}
Output:D:\java>javac replacechar.java
D:\java>java replacechar
enter string:-coconut
enter character you want to replace it:-c
enter character you want to change it:-t
origional string=coconut
Replace string:-totonut
Name:-Radhe Polara
Class:-SYBCA(4th Sem)
Roll no:-135
Div:-c
Sub:-Java programming Language
23). Write java code to input 10 different names and arranges them in
alphabetical order.
import java.io.*;
class Stringmanipul
{
static String
name[]={"hardika","sneha","hiral","bhumi","amisha","nirali","neha","hiral","ashmita
","bhakti"};
public static void main(String args[])
{
String temp;
for(int i=0;i<name.length;i++)
{
for(int j=i+1;j<name.length;j++)
{
if(name[j].compareTo(name[i])<0)
{
temp=name[i];
name[i]=name[j];
name[j]=temp;
}
}
}
for(int i=0;i<name.length;i++)
{
System.out.println(name[i]);
}
}
}
Name:-Radhe Polara
Class:-SYBCA(4th Sem)
Roll no:-135
Div:-c
Sub:-Java programming Language
Output:-
D:\java>javac Stringmanipul.java
D:\java>java Stringmanipul
amisha
ashmita
bhakti
bhumi
hardika
hiral
hiral
neha
nirali
sneha
Name:-Radhe Polara
Class:-SYBCA(4th Sem)
Roll no:-135
Div:-c
Sub:-Java programming Language
MIMP
24). An example of thread Priority.
class A extends Thread
{
public void run()
{
System.out.println("thread A started");
for(int i=1;i<=5;i++)
{
System.out.println("i="+i);
}
System.out.println("exit A");
}
}
class B extends Thread
{
public void run()
{
System.out.println("thread B started");
for(int j=1;j<=5;j++)
{
System.out.println("j="+j);
}
System.out.println("exit B");
}
}
class C extends Thread
{
public void run()
{
System.out.println("thread C started");
for(int k=1;k<=5;k++)
{
System.out.println("k="+k);
}
System.out.println("exit C");
}
}
Name:-Radhe Polara
Class:-SYBCA(4th Sem)
Roll no:-135
Div:-c
Sub:-Java programming Language
class ThreadPri
{
public static void main(String args[])
{
A obj1=new A();
B obj2=new B();
C obj3=new C();
obj3.setPriority(Thread.MAX_PRIORITY);
obj2.setPriority(obj1.getPriority()+1);
obj1.setPriority(Thread.MIN_PRIORITY);
obj1.start();
obj2.start();
obj3.start();
}
}
Output:D:\java>javac ThreadPri.java
D:\java>java ThreadPri
thread A started
thread C started
thread B started
k=1
i=1
k=2
j=1
k=3
i=2
i=3
i=4
i=5
exit A
k=4
j=2
k=5
exit C
j=3
j=4
j=5
exit B
Name:-Radhe Polara
Class:-SYBCA(4th Sem)
Roll no:-135
Div:-c
Sub:-Java programming Language
MIMP
25). Create an applet which displays text at different location with rectangle.
Rectangle should be inside circle and triangle.
import java.applet.*;
import java.awt.*;
public class rect extends Applet
{
public void paint(Graphics g)
{
g.drawRect(80,150,250,300);
g.drawOval(80,150,250,300);
int n=3;
int x[]=new int[n];
int y[]=new int[n];
x[0]=200;
y[0]=150;
x[1]=110;
y[1]=380;
x[2]=310;
y[2]=380;
g.drawPolygon(x,y,n);
g.drawString("Rectangle",110,160);
g.drawString("Rectangle",240,160);
}
}
Output:-
D:\java>javac rect.java
D:\java>
Name:-Radhe Polara
Class:-SYBCA(4th Sem)
Roll no:-135
Div:-c
Sub:-Java programming Language
Html file:<html>
<head>
</head>
<body>
<applet code="rect.class" height=100% width=100%>
</applet>
</body>
</html>
Output:-
Related documents