Вы находитесь на странице: 1из 75

index

Sr Name of the program Page date remarks


no. no.
Program to display only odd values between 1 4
1. to 20 in descending order?
Write a java program using two classes, first 5&6
2. class should display the rectangle and the
second class should display he area of circle?
Write a java program using sum of the 2*2 7&8
3. array?
Write a java program for taking input marks of 9&10
4. three student for three subject ? Calculate
average of each student and display the lowest
average?
Write a java program to sort following string in 11&12
5. ascending order
MNO DEF ABC GHI JKL?
Write a java program using applet to display 13&14
6. current date using Date()?
Write a java program to display output as 15
7. 9A1B 8A2B 7A3B 6A4B?
Write a java program to calculate square and 16
8. square root of given number using two classes?
create an applet to display number between 1 17&18
9. to10 sequence at the same location after the
interval of 2 seconds?
Write a java program to show multiple 19,20
10. inheritance using interface?
Write a java program to pass a string 21&22
11. parameter to applet and display that string in
upper case on applet window?
Write a java program to calculate factorial of 23
12. given input number?
Write a java program to generate or display 34&25
13. prime numbers in between 1 to 20 in
descending order?
Write a java program using applet which 26&27
14. displays the length of string?
Write a java program to reverse the given 28&29
15. numbers?
calculate an interface random number with 30&31
16. one function as: void digit()?
Write a program to get input of basic salary, 32&33
17. calculate the following:
HRA=7.5%
TA=12.5%
DA=29.10%
Ptax=9.12%
Itax=3.17%

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.

Write a program to draw line , circle, 37&38


19. rectangle?
Write a program to display any three math 39
20. function?
Write a program to find average of consecutive 40&41
21. n odd numbers & even numbers?
Write a program to find all the numbers 42
22. between 1 to 70 which are divisible by 7?
Write a program to print 2loyd’s triangle as 43&44
23. shown below:
1
23
456
7 8 9 10?

Write a program to get following output: 45&46


24. 1
2 2
3 3 3
4 4 4 4
5 5 5 5 5

create an interface calculate with one function 47&48


25. as :
void add(int x, int y)
create a java program to use above
interface to display addition of two integer
values?

Write a program to get following output : 49&50


26. *
* *
* * *
* * * *
* * * * *

Write a program to swap two variable’s 51&52


27. without using third variable?
Write a program to get input of one int and one 53&54
28. double type value?
Write a program to display fiboncci series ? 55&56
29.
Write a program todemonstrate the concept of 57-59
30. method overloading ?

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

{ public static void main(String arg[])

System.out.println("odd values between 1 to 20 in desending


order ");

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

void display(double l, double b )

double a;

a=b;

System.out.println("\n area of rectannngle is \t"+a);

class circle

void display(int r)

double pi=3.14;

System.out.println("\n area of circle is \t\t"+(pi*r*r));

class demo1

5
{

public static void main (String args[])

rectangle r=new rectangle();

circle c=new circle();

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

public static void main(String args [])

Scanner s=new Scanner (System.in);

Int arr[][]=new int [2][2];

int r,c,sum=0;

System.out.println("Enter 2*2 matrix values");

for (r=0;r<=1;r++)

for(c=0;c<=1;c++)

arr[r][c]=s.nextInt();

sum = sum+arr[r][c];

System.out.println("2*2array sum is \t"+sum);

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

{ public static void main(String args[])

{ Scanner s=new Scanner(System.in);

int arr[][] = new int[3][3];

int r,c;

double sum=0,min;

double avg[] = new double[3];

for(r=0;r<3;r++)

System.out.println("enter"+(r+1)+" student marks");

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
{

System.out.println((r+1)+"student average is\t"+avg[r]);

if(r!=0)

if(min>avg[r])

min=avg[r];

System.out.println("lowest average in\t"+min);

Signature

10
Aim: To Study string sort.
/*5.Write a java program to sort following string in ascending order

MNO DEF ABC GHI JKL? */

import java.util.Scanner;

class stringsort

public static void main(String args[])

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.*;

public class sysdate extends Applet

{ public void paint(Graphics g)

Date date=new Date();

String str;

g.drawString("Current System Date ls",50,40);

str= String.valueOf(date);

g.drawString(str,70,70);

HTML CODE:

<html/><head><tittle>Applet Exammple</title></head>

<body><applet code=sysdate.class width=400 height=200></applet

</body>

</html>

13
Signature

14
Aim: To Study for loop.
/*7.Write a java program to display output as

9A1B 8A2B 7A3B 6A4B? */

import java.util.Scanner;

class display

{ public static void main(String agrs[])

{ 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

static public float square(float x)

float y;

y=x*x;

return y;

static public float squareRoot(float x)

float y;

y=(float)Math.sqrt(x);

return y;

class Sqsqrt

public static void main(String args[])

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.*;

public class display extends Applet implements Runnable

int n=1;

Thread t=null;

public void init()

t=new Thread(this);

t.start();

public void run()

{ while(n<=10) try{ repaint();

Thread.sleep(2000);

++n;

} catch(Exception i){}

public void paint(Graphics g)

{ 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();

} class total implements sport,marks

{ Scanner s= new Scanner(System.in);

int a,b,c,sp,sum;

double avg;

public void input_marks()

{ a=s.nextInt();

b=s.nextInt();

c=s.nextInt();

} public void sport_marks()

{ sp=s.nextInt();

public void tot()

{ sum=a+b+c+sp;

avg=sum/4;

20
System.out.println("sum of all subject & sport marks\t"+sum);

System.out.println("avg marks are \t"+avg);

public class multiple

{ public static void main(String args[])

{ total t=new total();

System.out.println("enter 3 subject marks & sport marks\n");

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.*;

public class para extends Applet

String str;

public void init()

str=getParameter("temp");

public void paint (Graphics g)

g. drawString(str.toUpperCase(),50,40);

HTML CODE:

<html>

<head>

<title> My Internet Program 2</title>

</head>

<body bgColor="Yellow"fontcolor="Red"><Applet code="para.class"


height="300"width="400">
22
<param name="temp" value="KING">

</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

{ public static void main(String args[])

{ Scanner s=new Scanner(System.in);

System.out.println("\nenter number");

int n,f=1;

n=s.nextInt();

for(int a=n;a>=1;a--)

f=f*a;

System.out.println("\nfactorial of given number is\t"+f);

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

public static void main(String agrs[])

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.*;

public class length extends Applet

{ String str;

int l;

public void init()

{ str=getParameter("temp");

public void paint(Graphics g)

{ l=str.length();

g.drawString(String.valueOf(l),20,20);

g.drawString(str,60,60);

HTML CODE:

<html>

<head>

<title> My Internet Program 2</title>

</head>

<body><Applet code="length.class" height="300"width="400">

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

public static void main(String agrs[])

Scanner s=new Scanner(System.in);

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;

System.out.println("reverse number is\t"+rev);

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

{ public void digit();

class rand implements random_number

{ public void digit()

{ System.out.println((int)(100*Math.random()));

class interrand

{ public static void main(String args[])

{ rand r=new rand();

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

{ public static void main(String args[])

Scanner s=new Scanner(System.in);

double sal,hra,ta,da,ptax,itax,gross;

System.out.println("enter your salary");

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);

System.out.println("Gross salary is\t="+gross);

Signature

34
Aim: To Study an interface.
/*18.Write a program to create an interface as :

Interface area

Final static float pi=3.14f;

Float compute(float x, float y);

Implement it to calculate area of rectangle and circle. */

import java.util.*;

interface area

final static float pi=3.14f;

public float compute(float x,float y);

class rectangle implements area

float a;

public float compute(float x,float y)

a=x*y;

return a;

35
}

class circle implements area

float a;

public float compute(float x,float y)

a=pi*x*y;

return a;

class intarea

public static void main(String args[])

Scanner s=new Scanner(System.in);

float a,b,c;

rectangle r=new rectangle();

System.out.println("enter l& b values of rectangle");

a=s.nextFloat();

b=s.nextFloat();

c=r.compute(a,b);

System.out.println("area of rectangle is\t"+c);

a=s.nextFloat();

36
c=r.compute(a,a);

System.out.println("area of circle is\t"+c);

Signature

37
Aim: To Study an applet.
/*19.Write a program to draw line , circle , rectangle? */

import java.awt.*;

import java.applet.*;

public class ip2 extends Applet

public void paint(Graphics g)

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>

<head> <title> My Internet Program 2</title> </head>

<body><Applet code="ip2.class" height="300"width="500">

<param name="temp" value="KING">

</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

public static void main(String agrs[])

System.out.println("square root of 19 is\t\t"+Math.sqrt(19));

System.out.println("\nmaximum number between 10 &20


is\t"+Math.max(10,20));

System.out.println("\n4 to the power 3


is\t\t\t"+Math.pow(4,3));

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

{ public static void main(String args[])

Scanner s= new Scanner(System.in);

System.out.println("\n enter n'th number value");

int a=s.nextInt();

int even=0, odd=0,x=0,y=0;

for(int b=1;b<=a;b++)

{ if(b%2==0) { ++x;

even=even+b;

else { ++y;

odd=odd+b;

System.out.println("\neven value avg is\t"+(even/x));

System.out.println("\nodd value avg is\t"+(odd/y));

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

{ public static void main(String agrs[])

{ 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

public static void main (String args[])

int c=0;

for (int a=1;a<=4;a++)

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.*;

public class peramid2

public static void main (String args[])

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 :

void add(int x, int y)

create a java program to use above interface to display addition


of two integer values?*/

import java.util.*;

interface calculate

public void add(int x,int y);

class addition implements calculate

int c;

public void add(int x,int y)

c=x+y;

System.out.println("addition is\t"+c);

class intadd

public static void main (String args [])

48
Scanner s=new Scanner (System.in);

int x,y;

addition a=new addition();

System.out.println("enter two valus");

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.*;

public class peramid

public static void main (String args[])

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

{ private int a,b;

Scanner i=new Scanner(System.in);

void get()

System.out.print("\n Enter a value ");

a=i.nextInt();

System.out.print("\n Enter b value ");

b=i.nextInt();

} final void process()

{ a=a+b;

b=a-b;

a=a-b;

} void put()

{ System.out.print("\n \n A value= "+a);

System.out.print("\n \n B value= "+b);

} public class demo

52
{

public static void main (String args[])

swap x=new swap ();

x.get();

x.process();

System.out.print("\n After swap \n");

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

public static void main (String args[])

int a;

double d;

Scanner s=new Scanner (System.in);

System.out.println("enter 1 integer vaue");

a=s.nextInt();

System.out.println("\nenter 1 double value");

d=s.nextDouble();

System.out.println("\n \tinteger value is ="+a+"\t double value


is="+d);

54
Signature

55
Aim: To Study for loop
/*29. Write a program to display fiboncci series ?*/

import java.util.*;

class fibonacci

public static void main (String args[])

int a=0,b=1,c=0,n;

Scanner s=new Scanner (System.in);

System.out.println("enter n'th nubmer of series");

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

private float l,b,a;

void get(float x)

l=x;

b=x;

void get (float x,float y)

l=x;

b=y;

void process()

a=l*b;

void put()

58
System.out.print("\n\n lenth ="+l);

System.out.print("\n\n breadth ="+b);

System.out.print("\n\n area ="+a);

public class area

public static void main (String args[])

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;

public class oddeven

{ public void check(int n)

if(n%2==0)

System.out.println("even number");

else

System.out.println("odd number");

ACCESSING PACKEGE BCA

import java.io.*;

import java.util.*;

import bca.*;

public class demo3

public static void main(String args[])

int a,n;

oddeven c=new oddeven();

61
Scanner x=new Scanner (System.in);

System.out.println("Enter no. to check even or odd");

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

{ public static void main (String args[])

Scanner s=new Scanner(System.in);

System.out.print("enter choice 1.MCA 2.BCA 3.B.sc");

int a=s.nextInt();

switch(a)

{ case 1:

{ System.out.println("fees for MCA\t 60000 per year");

System.out.println("duration\t 3 years");

break;

} case 2:

{ System.out.println("fees for BCA\t 16000 per


year");

System.out.println("duration\t 3 years");

break;
63
} case 3:

System.out.println("fees for B.sc\t 20000 per year");

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

{ public static void main(String agrs[])

Scanner s=new Scanner(System.in);

int arr[][]=new int[3][3];

int col[]=new int[3];

int r,c;

System.out.println("enter 3*3 matrix values");

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.*;

public class demoapp extends Applet

{ public void paint(Graphics g)

{ 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>

<applet code=demoapp.class width=400 height =200></applet>

</body></html>

67
Signature

68
Aim: To Study thread
/*35. Write a program to display continuosly current time using
thread?*/

import java.util.Date;

class current extends Thread

Date date =new Date();

Boolean b =true;

public void run()

{ while(b)

{ try

{ Date date =new Date();

System.out.println(date);

sleep(1000);

catch(Exception er){}

class currenttime

{ public static void main(String agrs[])

{ current c =new current();

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

public static void main(String args[])

Scanner in= new Scanner(System.in);

System.out.println("Marks in 5 subjects: ");

int a[]=new int[5];

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
}

float avg = tot/5;

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 10: grade="FCD";

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
}

System.out.println("Gread: " +grade);

Signature

73
Aim: To Study applet
/*37,38. Write a programto fill colors in shapes using applet.aa ?*/

import java.applet.*;

import java.awt.*;

public class aa extends Applet

public void paint(Graphics g)

setBackground(Color.yellow);

Color coj=new Color(242,21,225);

setForeground(coj);

g.fillOval(50,100,100,100);

g.fillRect(250,100,100,100);

HTML CODE:

<html>

<head>

<title> My Internet Program 2</title>

</head>

<body><Applet code="aa.class"
height="300"width="500"></Applet></body>

</head> */

74
Signature

75

Вам также может понравиться