Академический Документы
Профессиональный Документы
Культура Документы
1
Write a program to create an interface as : 34,35
18. Interface area
{ &36
Final static float pi=3.14f;
Float compute(float x, float y);
}
Implement it to calculate area of rectangle and
circle.
2
Create a package class BCA with one member 60&61
31. function? Write a program to use this class?
Write a program to display the following 62&63
32. menu:
MCA
BCA
B.SC
Accept the choice of course and display fees
and duration of selected course using switch
case?
Write a program to get input 3*3 int array? 64&65
33. Calculate and display sum of each column?
Write a program to demonstrate concept of 66&67
34. Applet?
Write a program to display continuosly current 68&69
35. time using thread?
Write a program to get input marks of five 70,71,
36. subjects? Calculate total and average, display
the result with grade? 72&73
Write a programto fill colors in shapes using 74&75
37. applet.
3
Aim: To Study for loop.
/*1.Program to display only odd values between 1 to 20 in descending
order? */
import java.io.*;
import java.util.*;
class odd_d
for(int a=19;a>=1;a=a-2)
System.out.println(a);
Signature
4
Aim: To Study Classes & Objects.
/*2.Write a java program using two classes, first class should display
the rectangle and the second class should display he area of circle? */
import java.io.*;
import java.util.*;
class rectangle
double a;
a=b;
class circle
void display(int r)
double pi=3.14;
class demo1
5
{
r.display(4.0,5.0);
c.display(2);
Signature
6
Aim: To Study 2d array.
/*3.Write a java program using sum of the 2*2 array? */
import java.util.Scanner;
class array
int r,c,sum=0;
for (r=0;r<=1;r++)
for(c=0;c<=1;c++)
arr[r][c]=s.nextInt();
sum = sum+arr[r][c];
7
Signature
8
Aim: To Study nested for.
/*4.Write a java program for taking input marks of three student for
three subject . Calculate average of each student and display the
lowest average? */
import java.util.Scanner;
class threesub
int r,c;
double sum=0,min;
for(r=0;r<3;r++)
for(c=0;c<=2;c++)
{ arr[r][c]=s.nextInt();
sum=sum+arr[r][c];
avg[r] = sum/3;
sum=0;
min=avg[0];
for(r=0;r<=2;r++)
9
{
if(r!=0)
if(min>avg[r])
min=avg[r];
Signature
10
Aim: To Study string sort.
/*5.Write a java program to sort following string in ascending order
import java.util.Scanner;
class stringsort
String s[]={"MNO ", " DEF ", " ABC ", " GHI ", " JKL "};
String t;
for(int a=0;a<=4;a++)
for(int b=a+1;b<=4;b++)
if(s[a].compareTo(s[b])>0)
t=s[a];
s[a]=s[b];
s[b]=t;
for(int a=0;a<=4;a++)
11
System.out.print(s[a]);
Signature
12
Aim: To Study applet.
/*6.Write a java program using applet to display current date using
Date()? */
import java.util.Date;
import java.applet.*;
import java.awt.*;
String str;
str= String.valueOf(date);
g.drawString(str,70,70);
HTML CODE:
<html/><head><tittle>Applet Exammple</title></head>
</body>
</html>
13
Signature
14
Aim: To Study for loop.
/*7.Write a java program to display output as
import java.util.Scanner;
class display
{ int d=9,b=1;
for(int a=0;a<=3;a++)
System.out.println((d--)+"A"+(b++)+"B");
Signature
15
Aim: To Study while loop.
/*8.Write a java program to calculate square and square root of given
number using two classes? */
import java.lang.Math;
class SquareAndSquareRoot
float y;
y=x*x;
return y;
float y;
y=(float)Math.sqrt(x);
return y;
class Sqsqrt
16
float num=25.0f;
float a,b;
a=SquareAndSquareRoot.squareRoot(num);
b=SquareAndSquareRoot.square(num);
System.out.println("a="+a);
System.out.println("b="+b);
Signature
17
Aim: To Study applet.
/*9.create an applet to display number between 1 to10 sequence at
the same location after the interval of 2 seconds? */
import java.awt.*;
import java.applet.*;
int n=1;
Thread t=null;
t=new Thread(this);
t.start();
Thread.sleep(2000);
++n;
} catch(Exception i){}
{ g.drawString(String.valueOf(n),200,50);
18
}
Signature
19
Aim: To Study multiple inheritance using
interface.
/*10.Write a java program to show multiple inheritance using
interface? */
import java.util.*;
interface marks
{ void input_marks();
} interface sport
{ void sport_marks();
int a,b,c,sp,sum;
double avg;
{ a=s.nextInt();
b=s.nextInt();
c=s.nextInt();
{ sp=s.nextInt();
{ sum=a+b+c+sp;
avg=sum/4;
20
System.out.println("sum of all subject & sport marks\t"+sum);
t.input_marks();
t.sport_marks();
t.tot();
Signature
21
Aim: To Study applet.
/*11.Write a java program to pass a string parameter to applet and
display that string in upper case on applet window? */
import java.awt.*;
import java.applet.*;
String str;
str=getParameter("temp");
g. drawString(str.toUpperCase(),50,40);
HTML CODE:
<html>
<head>
</head>
</Applet>
</body>
</head>
Signature
23
Aim: To Study for loop.
/*12.Write a java program to calculate factorial of given input
number? */
import java.util.*;
class fact
System.out.println("\nenter number");
int n,f=1;
n=s.nextInt();
for(int a=n;a>=1;a--)
f=f*a;
Signature
24
Aim: To Study nested for loop.
/*13.Write a java program to generate or display prime numbers in
between 1 to 20 in descending order? */
import java.util.Scanner;
class prime
for(int a=20;a>=1;a--)
int flag=0;
for(int b=2;b<a;b++)
if(a%b==0)
flag=1;
break;
if(flag==0)
System.out.println(a);
25
}
Signature
26
Aim: To Study applet.
/*14.Write a java program using applet which displays the length of
string? */
import java.awt.*;
import java.applet.*;
{ String str;
int l;
{ str=getParameter("temp");
{ l=str.length();
g.drawString(String.valueOf(l),20,20);
g.drawString(str,60,60);
HTML CODE:
<html>
<head>
</head>
27
<param name="temp" value="King">
</Applet></body></head>
Signature
28
Aim: To Study while loop.
/*15.Write a java program to reverse the given numbers? */
import java.util.Scanner;
class reverse
System.out.println("enter 1 number");
int a=s.nextInt();
int t,rev=0;
while(a>0)
t=a%10;
rev=(rev*10)+t;
a=a/10;
29
Signature
30
Aim: To Study an interface.
/*16.calculate an interface random number with one function as: void
digit()
create a java program to use above interface to display only two digits
random integer value? */
import java.util.*;
interface random_number
{ System.out.println((int)(100*Math.random()));
class interrand
r.digit();
31
Signature
32
Aim: To Study general program.
/*17.Write a program to get input of basic salary, calculate the
following:
HRA=7.5%
TA=12.5%
DA=29.10%
Ptax=9.12%
Itax=3.17%
*/
import java.util.*;
class al
double sal,hra,ta,da,ptax,itax,gross;
sal=s. nextDouble();
hra=sal*0.075;
ta=sal*0.125;
da=sal*0.291;
ptax=sal*0.0912;
itax=sal*0.0317;
gross=sal+hra+ta+da+ta*itax;
33
System.out.println("basic salary is\t="+sal);
System.out.println("HRA is\t="+hra);
System.out.println("TA is\t="+ta);
System.out.println("DA is\t="+da);
System.out.println("ptax is\t="+ptax);
System.out.println("ltax is\t="+itax);
Signature
34
Aim: To Study an interface.
/*18.Write a program to create an interface as :
Interface area
import java.util.*;
interface area
float a;
a=x*y;
return a;
35
}
float a;
a=pi*x*y;
return a;
class intarea
float a,b,c;
a=s.nextFloat();
b=s.nextFloat();
c=r.compute(a,b);
a=s.nextFloat();
36
c=r.compute(a,a);
Signature
37
Aim: To Study an applet.
/*19.Write a program to draw line , circle , rectangle? */
import java.awt.*;
import java.applet.*;
g.setColor(Color.yellow);
g.fillOval(100,100,180,180);
g.setColor(Color.pink);
g.drawLine(10,50,500,50);
g.setColor(Color.red);
g.fillRect(300,100,160,150);
HTML CODE:
<html>
</Applet></body></head></html>
38
Signature
39
Aim: To Study math function.
/*20.Write a program to display any three math function? */
import java.util.*;
class math
Signature
40
Aim: To Study for loop.
/*21.Write a program to find average of consecutive n odd numbers &
even numbers?*/
import java.util.*;
class consec
int a=s.nextInt();
for(int b=1;b<=a;b++)
{ if(b%2==0) { ++x;
even=even+b;
else { ++y;
odd=odd+b;
41
Signature
42
Aim: To Study for loop.
/*22.Write a program to find all the numbers between 1 to 70 which
are divisible by 7 ? */
import java.util.*;
class seven
{ for(int b=1;b<=70;b++)
{ if(b%7==0)
{ System.out.println(b);
Signature
43
Aim: To Study nested for loop.
/*23.Write a program to print floyd’s triangle as shown below:
23
456
7 8 9 10 ? */
import java.util.*;
class pattern
int c=0;
for(int b=1;b<=a;b++)
System.out.print(++c+" ");
System.out.print("\n\n\n");
44
Signature
45
Aim: To Study nested for loop.
/*24.Write a program to get following output:
2 2
3 3 3
4 4 4 4
5 5 5 5 5 */
import java.io.*;
import java.util.*;
int i, j, k, space=4;
for (i=1;i<=5;i++)
for(k=1;k<=space;k++)
System.out.print(" ");
for(j=1;j<=i;j++)
46
System.out.print(" "+i);
System.out.print("\n\n");
space--;
Signature
47
Aim: To Study an interface.
/*25.create an interface calculate with one function as :
import java.util.*;
interface calculate
int c;
c=x+y;
System.out.println("addition is\t"+c);
class intadd
48
Scanner s=new Scanner (System.in);
int x,y;
x=s.nextInt();
y=s.nextInt();
a.add(x,y);
Signature
49
Aim: To Study nested for loop.
/*26.Write a program to get following output:
* *
* * *
* * * *
* * * * * */
import java.io.*;
import java.util.*;
int i, j, k, space=4;
for (i=1;i<=5;i++)
for(k=1;k<=space;k++)
System.out.print(" ");
for(j=1;j<=i;j++)
System.out.print(" "+"*");
50
}
System.out.print("\n\n");
space--;
Signature
51
Aim: To Study general program.
/*27.Write a program to swap two variable’s without using third
variable? */
import java.io.*;
import java.util.*;
class swap
void get()
a=i.nextInt();
b=i.nextInt();
{ a=a+b;
b=a-b;
a=a-b;
} void put()
52
{
x.get();
x.process();
x.put();
Signature
53
Aim: To Study general program.
/*28. Write a program to get input of one int and one double type
value?*/
import java.util.*;
class input
int a;
double d;
a=s.nextInt();
d=s.nextDouble();
54
Signature
55
Aim: To Study for loop
/*29. Write a program to display fiboncci series ?*/
import java.util.*;
class fibonacci
int a=0,b=1,c=0,n;
n=s.nextInt();
System.out.println(a);
System.out.println(b);
for(int x=1;x<=n-2;x++)
c=a+b;
System.out.println(c);
a=b;
b=c;
56
Signature
57
Aim: To Study method overloading
/*30. Write a program to demonstrate the concept of method
overloading ?*/
import java.io.*;
class overloading
void get(float x)
l=x;
b=x;
l=x;
b=y;
void process()
a=l*b;
void put()
58
System.out.print("\n\n lenth ="+l);
overloading o1,o2;
o1=new overloading();
o2=new overloading();
o1.get(15.5f);
o1.process();
o1.put();
o2.get(15.0f,16.5f);
o2.process();
o2.put();
59
Signature
60
Aim: To Study package
/*31. Create a package class BCA with one member function? Write a
program to use this class?*/
package bca;
if(n%2==0)
System.out.println("even number");
else
System.out.println("odd number");
import java.io.*;
import java.util.*;
import bca.*;
int a,n;
61
Scanner x=new Scanner (System.in);
n=x.nextInt();
c.check(n);
Signature
62
Aim: To Study of switch case
/*32. Write a program to display the following menu:
MCA
BCA
B.SC
Accept the choice of course and display fees and duration of selected
course using switch case?*/
import java.util.*;
class wh
int a=s.nextInt();
switch(a)
{ case 1:
System.out.println("duration\t 3 years");
break;
} case 2:
System.out.println("duration\t 3 years");
break;
63
} case 3:
System.out.println("duration\t 3 years");
break;
} default:
System.out.println("invalid input");
Signature
64
Aim: To Study switch case
/*33. Write a program to get input 3*3 int array? Calculate and display
sum of each column?*/
import java.util.*;
class colarray
int r,c;
for(r=0;r<=2;r++)
{ for(c=0;c<=2;c++)
{ arr[r][c]=s.nextInt();
if(c==0)
col[c]+=arr[r][c];
else if(c==1)
col[c]+=arr[r][c];
else
col[c]+=arr[r][c];
65
for(r=0;r<=2;r++)
{ System.out.print("\n");
for(c=0;c<=2;c++)
System.out.print(arr[r][c]+"\t");
System.out.print("\n");
for(c=0;c<3;c++)
System.out.print(col[c]+"\t");
}
}
Signature
66
Aim: To Study applet
/*34. Write a program to demonstrate concept of Applet?*/
import java.awt.*;
import java.applet.*;
{ g.setColor(Color.RED);
g.drawString("Stay",40,80);
g.setColor(Color.GREEN);
g.drawString("Positive",40,150);
HTML CODE:
<html><head><title>Applet Example</title>
</head><body>
</body></html>
67
Signature
68
Aim: To Study thread
/*35. Write a program to display continuosly current time using
thread?*/
import java.util.Date;
Boolean b =true;
{ while(b)
{ try
System.out.println(date);
sleep(1000);
catch(Exception er){}
class currenttime
c.start();
69
}
Signature
70
Aim: To Study nested if
/*36. Write a program to get input marks of five subjects? Calculate
total and average, display the result with grade?*/
import java.io.*;
import java.util.*;
class bca1
int tot=0;
boolean flag=false;
for(int i=0;i<5;i++)
System.out.print("Subject["+(i+1)+"]: ");
a[i] = in.nextInt();
if(a[i]<25)
flag=true;
tot+=a[i];
71
}
System.out.println("Total: "+tot);
System.out.println("Percentage: "+avg+"%");
if(flag)
System.out.println("Status: FAIL");
return;
String grade="";
switch(Math.round(avg/10))
case 9: grade="FCD";
break;
case 8: grade="FC";
case 7: grade="FC";
break;
case 6 : grade="SC";
case 4 : grade="SC";
break;
case 3 : grade="C";
break;
default : grade="Fail";
72
}
Signature
73
Aim: To Study applet
/*37,38. Write a programto fill colors in shapes using applet.aa ?*/
import java.applet.*;
import java.awt.*;
setBackground(Color.yellow);
setForeground(coj);
g.fillOval(50,100,100,100);
g.fillRect(250,100,100,100);
HTML CODE:
<html>
<head>
</head>
<body><Applet code="aa.class"
height="300"width="500"></Applet></body>
</head> */
74
Signature
75