Skip to main content

java lab 2nd semester

SYED AMMAL ARTS AND SCIENCE COLLEGE

 (Affiliated to Alagappa University - Karaikudi)

NAAC Accredited with “B” Grade

Koottampuli, Ramanathapuram - 623513

 

 

DEPARTMENT OF INFORMATION TECHNOLOGY

 

 

 

Logo 

 

 

 

 

 

Reg. No :

 

 

Name    :

 

 

 

 

Academic Year

 

  2024 – 2025

 

 

SYED AMMAL ARTS AND SCIENCE COLLEGE

 (Affiliated to Alagappa University - Karaikudi)

NAAC Accredited with “B” Grade

DEPARTMENT OF INFORMATION TECHNOLOGY

 

Logo 

 

Certified a Bonafide record of practical work done on 23BIT2P1-JAVA PROGRAMMING LAB by _______________________________ Reg.No.

__________________ of B.Sc. (Information Technology)I year during II Semester APRIL, 2025.

 

                                                                                                             

Head of the Department                                                                       Staff  In-charge

             

                                                                                     

       Submitted at the time of B.Sc. Degree practical Examination being held on _____________ in Syed Ammal Arts and Science College, Koottampuli.

 

 

Internal Examiner                                                                                            External Examiner  

 

INDEX

           

S.NO

 

          DATE

 

                      PROGRAM  NAME

PAGE NO

SIGNATURE

 

1.

24.12.2024

BIGGEST AMONG TWO NUMBER

1

 

 

2.

26.12.2024

STUDENT MARKLIST

2

 

 

3.

02.01.2025

EB BILL CALCULATION

4

 

 

4.

03.01.2025

FACTORIAL

5

 

 

5.

09.01.2025

MULTIPLICATION TABLE

6

 

 

6.

10.01.2025

FIBONACCI SERIES GENERATION

7

 

 

7.

20.01.2025

PRIME OR NOT

8

 

 

8.

21.01.2025

PERFECT OR NOT

9

 

 

9.

27.01.2025

ARMSTRONG OR NOT

10

 

 

10.

28.01.2025

REVERSE THE DIGIT

11

 

 

11.

03.02.2025

SUM OF DIGIT

12

 

 

12.

04.02.2025

DESCENDING ORDER

13

 

 

13.

10.02.2025

MATRIX ADDITION

15

 

 

14.

12.02.2025

MATRIX SUBTRACTION

17

 

 

15. 

18.02.2025

STRING HANDLING FUNCTION

19

 

 

16.

19.02.2025

PALINDROME OR NOT

20

 

 

17.

25.02.2025

STRING SORTING

21

 

 

18.

26.02.2025

AVERAGE CALCULATION

22

 

 

19.

04.03.2025

SUM OF MATRIX ITEMS

23

 

 

20.

05.03.2025

CALCULATOR

24

 

 

21.

11.03.2025

SINGLE INHERITANCE

27

 

 

22.

18.03.2025

HUMAN FACE

29

 

 

23.

19.03.2025

NATIONAL FLAG

30

 

 

24.

19.03.2025

BAR CHART

32

 

 

 

 

 

 

 

 

 

 

 

 


EX.NO: 1                                 BIGGEST AMONG TWO NUMBER                                   DATE:24.12.2025

 

Aim

Write a Program to find the biggest among two number using command line argument. Source Code

class LNum

{ public static void main (String args[])

{

int a=Integer.parseInt(args[0]); int b=Integer.parseInt(args[1]); if(a>b)

{

System.out.println("A Is Largest Number...");

} else   

{

 System.out.println("B Is Largest number...");  }

}

}

 

Output


 

 

 

Result

The above Program has been Completed Successfully

 

 

 

 

 

 

 

 

EX.NO: 2                                 STUDENT MARKLIST                                                        DATE:26.12.2025

 

Aim

Write a mark list program to find the total, average, result and grade

Source Code import java.util.Scanner; public class Marklist

{     public static void main(String args[])

    {

     int marks[] = new int[6];

        int i;

        float total=0, avg;

        Scanner scanner = new Scanner(System.in);        for(i=0; i<6; i++) { 

           System.out.print("Enter Marks of Subject"+(i+1)+":");

           marks[i] = scanner.nextInt();

           total = total + marks[i];

        }

        scanner.close();         avg = total/6;


        System.out.print("The student Grade is: ");         if(avg>=80)

        {

            System.out.print("A");

        }

        else if(avg>=60 && avg<80)

        {

           System.out.print("B");

        } 

        else if(avg>=40 && avg<60)

        {

            System.out.print("C");

        }         else

        {

            System.out.print("D");

        }

    }

}

 

 

 

 

 

 

 

 

Output

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Result

The above Program has been Completed Successfully

 

 

 

 

 

 

EX.NO: 3                                 EB BILL CALCULATION                                                   DATE:02.01.2025

 

Aim:

Write a program to prepare EB Bill Calculation

Source Code import java.util.Scanner; public class EBbill 

{     public static void main(String[] args) 

{

        int units;         double billToPay = 0;

 

        Scanner sc = new Scanner(System.in);

        System.out.println("Enter the number of units for calculating the electricity bill:");         units = sc.nextInt();

 

        if (units < 100) {

            billToPay = units * 1.20;         } else if (units < 300) {

            billToPay = 100 * 1.20 + (units - 100) * 2;

        } else if (units >= 300) {

            billToPay = 100 * 1.20 + 200 * 2 + (units - 300) * 3;

        }


 

        System.out.println("The electricity bill for " + units + " units is: $" + billToPay);

    }

}

 

Output

 

 

 

 

Result

The above Program has been Completed Successfully

 

 

 

 


                 4                                           FACTORIAL                             DATE:03.01.2025

Aim

Write a program to find the factorial value of the given number Source Code

 

import java.io.*; public class

Factorial1

{

 

public static void main(String args[])throws IOException

 

{

 

int n,i,fact=1;

 

BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

System.out.println("Enter the number:"); n=Integer.parseInt(br.readLine()); for(i=1;i<=n;i++)

{

 

fact=fact*i;

 

}

 

System.out.println("Factorial value:"+fact);

 

}

}

 

Output

 

 

 

 

Result

The above Program has been Completed Successfully

 

EX.NO: 5                                 MULTIPLICATION TABLE                                                DATE:09.01.2025

 

Aim

Write a Program to print Multiplication Table

Source Code

import java.io.*; public class Multable {     public static void main(String[] args)throws IOException 

{ int num;

BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); 

System.out.println("Enter the number:"); num=Integer.parseInt(br.readLine());

for (int i = 1; i <= 10; ++i)

{

System.out.printf("%d * %d = %d%n", num, i, num * i);

        }

    }

}

 

Output


 

 

 

 

 

Result

The above Program has been Completed Successfully

 

 

 

 

                 6                                FIBONACCI SERIES GENERATION  DATE:10.01.2025

Aim

Write a Program to print Fibonacci series

Source Code

import java.io.*;  public class Fibo

{ public static void main(String args[])throws IOException

{

BufferedReader br=new BufferedReader(new InputStreamReader (System.in));

String s; int n,i,f1=-1,f2=1,f3=0;

System.out.println("Enter the n values"); s=br.readLine(); n=Integer.parseInt(s);

System.out.println (" Fibonacci series:"); for(i=0; i<=n; i++)

{ f3=f1+f2;

System.out.println (f3); f1=f2; f2=f3;

}

}

} Output 

 

 

 

 

Result

The above Program has been Completed Successfully


                 7                                 PRIME OR NOT                                   DATE:20.01.2025

Aim

Write a Program to find the given number is prime or not 

Source Code import java.util.Scanner;

public class PrimeN {

 

  public static void main(String[] args) {

 

Scanner sc = new Scanner(System.in);         System.out.print("Enter the number: ");         long num = sc.nextLong();

 

    boolean flag = false;     for (int i = 2; i <= num / 2; ++i) {       // condition for nonprime number       if (num % i == 0) {         flag = true;         break;

      }     }

     if (!flag)

      System.out.println(num + " is a prime number.");     else

      System.out.println(num + " is not a prime number.");

  }

}

 

Output

 

 

 

Result

The above Program has been Completed Successfully

 

                 8                                 PERFECT OR NOT                              DATE:21.01.2025

Aim

Write a Program to find the given number is perfect or not

Source Code import java.util.Scanner; public class PerfectN{

    // Function to check if the given number is perfect or not     static long isPerfect(long num) {         long sum = 0;         for (int i = 1; i <= num / 2; i++) {             if (num % i == 0) {                 sum += i; // Calculate the sum of factors

            }

        }

        return sum;

    }

 

    public static void main(String[] args) {         Scanner sc = new Scanner(System.in);         System.out.print("Enter the number: ");         long n = sc.nextLong();         long sumOfFactors = isPerfect(n);         if (sumOfFactors == n) {

            System.out.println(n + " is a perfect number.");

        } else {

            System.out.println(n + " is not a perfect number.");

        }

    }

}

 

Output

 

 

 

 

Result

The above Program has been Completed Successfully

 

 

                 9                                 ARMSTRONG OR NOT                        DATE:27.01.2025

Aim

Write a Program to find the given number is Armstrong or not Source Code

import java.io.*;  public class Armst

{

 

public static void main(String args[])throws IOException

 

{

 

BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String s; int n,a,q,r,res=0;

System.out.println("Enter the any number"); s=br.readLine(); n=Integer.parseInt(s); a=n; while(n>0)

{ q=n/10;

r=n%10; res=res+(r*r*r);

n=q; } if(a==res)

System.out.println("This is an amstrong number"); else

System.out.println("This is not an amstrong number");

}

}

 

Output

 

 


                    0                               REVERSE THE DIGIT                         DATE:28.01.2025

Aim

Write a program to Reverse the Given number

Source Code

import java.io.*;  public class Revers

{

public static void main(String args[])throws IOException {

BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

String s;

int res, num,sum=0;

System.out.println("enter the number"); s=br.readLine(); num=Integer.parseInt(s);

System.out.println("enter the number to be reversed"); while(num>0)

{

 

res=num%10; sum=sum*10+res; num=num/10;

}

 

System.out.println(sum);

}

}

 

Output 

 

 

Result

The above Program has been Completed Successfully

 

 

 

 

 

 

                   1                               SUM OF DIGITS                                   DATE:03.02.2025

 

Aim

Write a program to find the Sum of Digits

Source Code import java.util.Scanner; public class sumofdigit{

    public static void main(String[] args) {         int number, digit, sum = 0;

        Scanner sc = new Scanner(System.in);         System.out.print("Enter the number: ");         number = sc.nextInt();         while (number > 0) {

            // Find the last digit of the given number             digit = number % 10; // 12%10=2             // Add the last digit to the variable 'sum'             sum += digit;//0+2=2

            // Remove the last digit from the number             number /= 10;//number=1

        }

        System.out.println("Sum of Digits: " + sum);

    }

}

 

Output 

 

 

 

Result

The above Program has been Completed Successfully

 

 

 

 

 

 

 

 

 

 

 

                    2                               DESCENDING ORDER                         DATE:04.02.2025

Aim

Write a java program to arrange the given numbers in descending order. Source Code

import java.io.*; class descend

{

public static void main(String args[])throws IOException {

BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int i,j,n,a[];

System.out.println("enter the number of elements to sort"); n=Integer.parseInt(br.readLine()); a=new int[100];

System.out.println("list it");

for(i=0;i<n;i++)

{

a[i]=Integer.parseInt(br.readLine());

}

for(i=0;i<n;i++)

{

for(j=i+i;j<n;j++)

{ int temp;  if(a[i]<a[j]) 

{ temp=a[i]; a[i]=a[j]; a[j]=temp;

}

}

}

System.out.println("after sorting"); for(i=0;i<n;i++)

{

System.out.println(a[i]);

}

}

}

 

 

 

 

 

 


Output 

 

 

 

 

 

Result

The above Program has been Completed Successfully

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

EX.NO: 13                               MATRIX ADDITION                                                           DATE:10.02.2025

 

Aim

Write program for Matrix Addition

Source Code import java.util.Scanner; class AddMatrix

{

public static void main(String args[])

{

int row, col,i,j;

Scanner in = new Scanner(System.in);

System.out.println("Enter the number of rows"); row = in.nextInt();

System.out.println("Enter the number columns"); col = in.nextInt(); int mat1[][] = new int[row][col]; int mat2[][] = new int[row][col]; int res[][] = new int[row][col];

System.out.println("Enter the elements of matrix1"); for ( i= 0 ; i < row ; i++ )


{ 

for ( j= 0 ; j < col ;j++ ) mat1[i][j] = in.nextInt();

System.out.println();

}

System.out.println("Enter the elements of matrix2"); for ( i= 0 ; i < row ; i++ )

{ for ( j= 0 ; j < col ;j++ )

mat2[i][j] = in.nextInt();

 

System.out.println();

} for ( i= 0 ; i < row ; i++ ) for ( j= 0 ; j < col ;j++ )

res[i][j] = mat1[i][j] + mat2[i][j] ;  System.out.println("Sum of matrices:-"); for ( i= 0 ; i < row ; i++ )

{  for ( j= 0 ; j < col ;j++ )

System.out.print(res[i][j]+"\t");

System.out.println();

}

}

}

Output 

 

 

 

 

Result

The above Program has been Completed Successfully

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 


                    4                               MATRIX SUBTRACTION                                                   DATE:12.02.2025

Write program for Matrix Subtraction

Source Code import java.util.Scanner;

 

class SubMatrix

{    public static void main(String args[])

   {

      int row, col,i,j;

      Scanner in = new Scanner(System.in);

 

      System.out.println("Enter the number of rows");       row = in.nextInt();

     

      System.out.println("Enter the number  columns");       col  = in.nextInt();

    

      int mat1[][] = new int[row][col];       int mat2[][] = new int[row][col];

      int res[][] = new int[row][col];

 

      System.out.println("Enter the elements of matrix1");

 

      for (  i= 0 ; i < row ; i++ )

       {   

    

            for ( j= 0 ; j < col ;j++ )

            mat1[i][j] = in.nextInt();

            

       }

      System.out.println("Enter the elements of  matrix2");

 

 

      for (  i= 0 ; i < row ; i++ )

       {

               

                  for ( j= 0 ; j < col ;j++ )                   mat2[i][j] = in.nextInt();         

      }

 

      for (  i= 0 ; i < row ; i++ )          for ( j= 0 ; j < col ;j++ )

             res[i][j] =  mat1[i][j]-mat2[i][j];   

 

      System.out.println("subtract  of  two matrices:-");

 

      for ( i= 0;i < row ;i++ )

       {  

                for ( j= 0 ; j < col ;j++ )

                System.out.print(res[i][j]+"\t");

             

         System.out.println();

       }  

   }

}

 

Output 

 

 

 

 

Result

The above Program has been Completed Successfully

 

 

 

 

 

 

 

 

 

 

 

 

 

 

                    5                               STRING HANDLING FUNCTION                                      DATE:18.02.2025

Write a program to perform the string operations using String class

Source Code

import java.util.Scanner; class Strings {   public static void main(String[] args) {         Scanner scanner = new Scanner(System.in);

        System.out.print("Enter a First string: ");

       String first = scanner.nextLine();     System.out.println("First String: " + first);

System.out.print("Enter a Second string: ");

     String second = scanner.nextLine();

    System.out.println("Second String: " + second);

     String joinedString = first.concat(second);

    System.out.println("Joined String: " + joinedString);

    System.out.print("Enter a more than one word: ");

String str1 = scanner.nextLine();

    System.out.println(str1.substring(0,10));   }

}

 

Output 

 

 

 

Result

The above Program has been Completed Successfully

             


                    6                               PALINDROME OR NOT                      DATE:19.02.2025

Write a java program to find the given string is palindrome or not.

Source Code

import java.io.*; import java.lang.*; import java.util.*; public class Palindrome

{

public static void main(String args[])throws IOException

{

BufferedReader s=new BufferedReader(new

InputStreamReader(System.in));

System.out.println("Enter the string you want to check:");

String myString=s.readLine();

StringBuffer buffer=new StringBuffer(myString); buffer.reverse();

String data=buffer.toString(); if(myString.equals(data))

{

System.out.println("given string is palindrome");

} else

{

System.out.println("given string is not palindrome");

}

}

}

 

Output 

 

 

 

 

Result

The above Program has been Completed Successfully

 

 

 

 

 

 

                    7                               STRING SORTING                               DATE:25.02.2025

Write a program to arrange the String an Ascending order.

Source Code

import java.util.Arrays;

import java.util.Scanner;

 

public class ascend17

{     public static String sortString(String inputString) 

{         char[] tempArray = inputString.toCharArray();         Arrays.sort(tempArray);         return new String(tempArray);

    }

 

    public static void main(String[] args) {

Scanner scanner = new Scanner(System.in);

        System.out.print("Enter a First string: "); String inputString = scanner.nextLine();

String outputString = sortString(inputString);

 

        System.out.println("Input String: " + inputString);

        System.out.println("Output String: " + outputString);

    }

}

 

Output 

 

 

 

Result

The above Program has been Completed Successfully

 

 

 

 

 

 

EX.NO: 18        FIND AVERAGE USING COMMAND LINE ARGUMENT  DATE:26.02.2025

 

 

 Aim

 

 Write a java program to accept n integers as command line arguments and find average 

 

Source Code

 

public class MyClass {     public static void main(String args[]) {

    

    int sum = 0;

     

    for(int i=0;i<args.length;i++)

    {

        sum +=Integer.parseInt(args[i]);

    }

 

    int average = sum / args.length;

    

    System.out.println("Average of " + args.length + " command line arguments is " + average);

    }


}

 

Output 

 

 

 

 

Result

The above Program has been Completed Successfully

 

 

 

 

 

 

 


EX.NO: 19       SUM OF MATRIX ITEMS IN ROWS AND COLUMNS                                                       DATE:04.03.2025

 

Aim 

Write a program to find the Sum of each Row in the given matrix Source Code public class Sum1 {

             

            public static void main(String[] args) {

                         

                        int i, j, rowsum, columnsum; 

             

                        int[][] Colsarr = {{11, 21, 31}, {41, 51, 61}, {71, 81, 91}};

                                        

                        for(i = 0; i < Colsarr.length; i++)

                        {

                                    rowsum = 0;                  columnsum = 0;

                                    for(j = 0; j < Colsarr[0].length; j++)

                                    {

                                                rowsum = rowsum + Colsarr[i][j];

                                                columnsum = columnsum + Colsarr[j][i];

                                    }


                                    System.out.println("\nThe Sum of Matrix Items "

                                                            + "in Row " + i + " = " + rowsum);

                                    System.out.println("\nThe Sum of Matrix Items "

                                                            + "in Column " + i + " = " + columnsum);

                        }

            }

}

 

Output 

 

 

 

Result

The above Program has been Completed Successfully

 

EX.NO: 20                                           CALCULATOR                         DATE:05.03.2025

 Aim 

Write a Java program that works as a simple calculator. Use a grid layout to arrange buttons for the digits and for the +, -,*, % operations. Add a text field to display the result. Handle any possible exceptions like divide by zero. Source Code import java.awt.*; import java.awt.event.*;

public class MyCalculator extends Frame implements ActionListener {     double num1,num2,result;

    Label lbl1,lbl2,lbl3;

    TextField tf1,tf2,tf3;     Button btn1,btn2,btn3,btn4;

    char op;     MyCalculator() {         lbl1=new Label("Number 1: ");

        lbl1.setBounds(50,100,100,30);

        

        tf1=new TextField();

        tf1.setBounds(160,100,100,30);

        

        lbl2=new Label("Number 2: ");

        lbl2.setBounds(50,170,100,30);

        

        tf2=new TextField();

        tf2.setBounds(160,170,100,30);

        

        btn1=new Button("+");

        btn1.setBounds(50,250,40,40);

 

        btn2=new Button("-");         btn2.setBounds(120,250,40,40);

 

        btn3=new Button("*");         btn3.setBounds(190,250,40,40);

 

        btn4=new Button("/");         btn4.setBounds(260,250,40,40);

        

        lbl3=new Label("Result : ");

        lbl3.setBounds(50,320,100,30);

        

        tf3=new TextField();

        tf3.setBounds(160,320,100,30);

 

        btn1.addActionListener(this);

        btn2.addActionListener(this);         btn3.addActionListener(this);         btn4.addActionListener(this);

        

        add(lbl1); add(lbl2); add(lbl3);         add(tf1);  add(tf2);  add(tf3);

        add(btn1); add(btn2); add(btn3); add(btn4);

 

        setSize(400,500);         setLayout(null);         setTitle("Calculator");

        setVisible(true);

        

    }

    

    public void actionPerformed(ActionEvent ae) {

        

        num1 = Double.parseDouble(tf1.getText());         num2 = Double.parseDouble(tf2.getText());

        

        if(ae.getSource() == btn1)

        {

            result = num1 + num2;

            tf3.setText(String.valueOf(result));

        }

        if(ae.getSource() == btn2)

        {

            result = num1 - num2;

            tf3.setText(String.valueOf(result));

        }

        if(ae.getSource() == btn3)

        {

            result = num1 * num2;

            tf3.setText(String.valueOf(result));

        }

        if(ae.getSource() == btn4)

        {

                result = num1 / num2;

                tf3.setText(String.valueOf(result));

        }     }

 

    public static void main(String args[]) {

        MyCalculator calc=new MyCalculator();

    }

}

 

 

 

 

 

 

 

Output 

 

 

 

Result

The above Program has been Completed Successfully

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

EX.NO: 21                                           SINGLE INHERITANCE          DATE:11.03.2025

 

Aim

Write a program using Single Inheritance.

Source Code

 

class Room

{ int Length, Breadth;

Room (int x, int y)

{

Length=x;

Breadth=y;

} int area () {

return (Length*Breadth);

}

}

class Room1 extends Room

{ int height;


Room1 (int x, int y, int z)

{

int volume ()

{

return (Length*Breadth*Height);

} }

class inhert

{

public static void main (String args[])

{

Room1 obj=new Room1(14,12,10);

int area1=obj.area (); int volume1=obj.volume();

System.out.println(“Area1 =”+area1);

System.out.println(“Volume =”+volume1);

}

}

 

 

 

 

 

 

Output 

 

 

 

Result

The above Program has been Completed Successfully

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

EX.NO: 22                                           HUMAN FACE                          DATE:18.03.2025

 

Aim 

Draw a Human Face using Applet

Source Code

import java.applet.*; 

import java.awt.*;  import java.lang.*;

/*<applet code=Face.class width=400 height=400></applet>*/  public class Face extends Applet

{

public void paint(Graphics g)

{

g.drawOval(40,40,120,150); 

g.drawOval(57,75,30,20); 

g.drawOval(110,75,30,20);

 g.fillOval(68,81,10,10);

 g.fillOval(121,81,10,10);

 g.drawOval(85,100,30,30); 

g.fillArc(60,120,75,40,180,180);


g.drawOval(25,92,15,30); 

g.drawOval(160,92,15,30);

}

 

}

 

Output 

 

 

 

Result

The above Program has been Completed Successfully

EX.NO: 23                                           NATIONAL FLAG                    DATE:19.03.2025

 

 

Aim  

Draw a national Flag using java applet 

Source Code import java.awt.*; import java.applet.*;

/*<applet code=Flags.class width=400 height=400></applet>*/ public class Flags extends Applet

{

public void paint(Graphics g)

{

g.fillOval(60,450,120,50);

g.fillOval(110,60,10,400);

g.setColor(Color.orange);

g.fillRect(120,80,150,30);

g.setColor(Color.white);

g.fillRect(120,110,150,30);

g.setColor(Color.green);


g.fillRect(120,140,150,30);

g.setColor(Color.blue);

g.drawOval(180,110,30,30); int t=0,x=195,y=125,n=24; double x1,y1,d,r=15; for(int i=0;i<=n;i++)

{

d=(double)t*3.14/180.0; x1=x+(double)r*Math.sin(d); y1=y+(double)r*Math.cos(d);

g.drawLine(x,y,(int)x1,(int)y1);

t+=360/24;

}

}

}

 

 

 

 

 

 

 

Output 

 

 

 

 

Result

The above Program has been Completed Successfully

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

EX.NO: 24                                           BAR CHART                             DATE:19.03.2025

 

import java.awt.*; import java.applet.*;

public class BarChart extends Applet

{ int n=0; String label []; int value []; public void init()

{ try {


n=integer.parsInt (getParameter(“columns”)); label=new String[n]; value = new int [n]; label[0]=getParameter (“label1”); label[1]=getParameter (“label2”); label[2]=getParameter (“label3); label[3]=getParameter (“label4”); value [0] =Integer.parseInt (getParameter (“c1”)); value [1] =Integer.parseInt (getParameter (“c2”)); value [2] =Integer.parseInt (getParameter (“c3”)); value [3] =Integer.parseInt (getParameter (“c4”));

}

catch (NumberFormatException e)

{

} }

public void paint (Graphics g)

{

for ( int i=0;i<n;i++)

{

g.setcolor(color.red);

g.drawstring(label [i],20,i*50+30); Year 1991 1992 1993 1994

 

Turnover(Rs Crores) 110 150 100 170

 

g.fillRect(50,i*50+10, value [i],40);

}

}

}

<html>

<applet

Code = BarChart.class

Width = 300

Height = 250>

<PARAM NAME = “columns” VALUE = “4”>

<PARAM NAME = “c1” VALUE =”110”>

<PARAM NAME = “c2” VALUE =”150”>

<PARAM NAME = “c3” VALUE =”100”>

<PARAM NAME = “c4” VALUE =”170”>

<PARAM NAME = “label1” VALUE =”91”>

<PARAM NAME = “label2” VALUE =”92”>

<PARAM NAME = “label3” VALUE =”93”>

<PARAM NAME = “label4” VALUE =”94”>

</applet> </html>

 

Output 

SYED AMMAL ARTS AND SCIENCE COLLEGE

 (Affiliated to Alagappa University - Karaikudi)

NAAC Accredited with “B” Grade

Koottampuli, Ramanathapuram - 623513

 

 

DEPARTMENT OF INFORMATION TECHNOLOGY

 

 

 

Logo 

 

 

 

 

 

Reg. No :

 

 

Name    :

 

 

 

 

Academic Year

 

  2024 – 2025

 

 

SYED AMMAL ARTS AND SCIENCE COLLEGE

 (Affiliated to Alagappa University - Karaikudi)

NAAC Accredited with “B” Grade

DEPARTMENT OF INFORMATION TECHNOLOGY

 

Logo 

 

Certified a Bonafide record of practical work done on 23BIT2P1-JAVA PROGRAMMING LAB by _______________________________ Reg.No.

__________________ of B.Sc. (Information Technology)I year during II Semester APRIL, 2025.

 

                                                                                                             

Head of the Department                                                                       Staff  In-charge

             

                                                                                     

       Submitted at the time of B.Sc. Degree practical Examination being held on _____________ in Syed Ammal Arts and Science College, Koottampuli.

 

 

Internal Examiner                                                                                            External Examiner  

 

INDEX

           

S.NO

 

          DATE

 

                      PROGRAM  NAME

PAGE NO

SIGNATURE

 

1.

24.12.2024

BIGGEST AMONG TWO NUMBER

1

 

 

2.

26.12.2024

STUDENT MARKLIST

2

 

 

3.

02.01.2025

EB BILL CALCULATION

4

 

 

4.

03.01.2025

FACTORIAL

5

 

 

5.

09.01.2025

MULTIPLICATION TABLE

6

 

 

6.

10.01.2025

FIBONACCI SERIES GENERATION

7

 

 

7.

20.01.2025

PRIME OR NOT

8

 

 

8.

21.01.2025

PERFECT OR NOT

9

 

 

9.

27.01.2025

ARMSTRONG OR NOT

10

 

 

10.

28.01.2025

REVERSE THE DIGIT

11

 

 

11.

03.02.2025

SUM OF DIGIT

12

 

 

12.

04.02.2025

DESCENDING ORDER

13

 

 

13.

10.02.2025

MATRIX ADDITION

15

 

 

14.

12.02.2025

MATRIX SUBTRACTION

17

 

 

15. 

18.02.2025

STRING HANDLING FUNCTION

19

 

 

16.

19.02.2025

PALINDROME OR NOT

20

 

 

17.

25.02.2025

STRING SORTING

21

 

 

18.

26.02.2025

AVERAGE CALCULATION

22

 

 

19.

04.03.2025

SUM OF MATRIX ITEMS

23

 

 

20.

05.03.2025

CALCULATOR

24

 

 

21.

11.03.2025

SINGLE INHERITANCE

27

 

 

22.

18.03.2025

HUMAN FACE

29

 

 

23.

19.03.2025

NATIONAL FLAG

30

 

 

24.

19.03.2025

BAR CHART

32

 

 

 

 

 

 

 

 

 

 

 

 


EX.NO: 1                                 BIGGEST AMONG TWO NUMBER                                   DATE:24.12.2025

 

Aim

Write a Program to find the biggest among two number using command line argument. Source Code

class LNum

{ public static void main (String args[])

{

int a=Integer.parseInt(args[0]); int b=Integer.parseInt(args[1]); if(a>b)

{

System.out.println("A Is Largest Number...");

} else   

{

 System.out.println("B Is Largest number...");  }

}

}

 

Output


 

 

 

Result

The above Program has been Completed Successfully

 

 

 

 

 

 

 

 

EX.NO: 2                                 STUDENT MARKLIST                                                        DATE:26.12.2025

 

Aim

Write a mark list program to find the total, average, result and grade

Source Code import java.util.Scanner; public class Marklist

{     public static void main(String args[])

    {

     int marks[] = new int[6];

        int i;

        float total=0, avg;

        Scanner scanner = new Scanner(System.in);        for(i=0; i<6; i++) { 

           System.out.print("Enter Marks of Subject"+(i+1)+":");

           marks[i] = scanner.nextInt();

           total = total + marks[i];

        }

        scanner.close();         avg = total/6;


        System.out.print("The student Grade is: ");         if(avg>=80)

        {

            System.out.print("A");

        }

        else if(avg>=60 && avg<80)

        {

           System.out.print("B");

        } 

        else if(avg>=40 && avg<60)

        {

            System.out.print("C");

        }         else

        {

            System.out.print("D");

        }

    }

}

 

 

 

 

 

 

 

 

Output

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Result

The above Program has been Completed Successfully

 

 

 

 

 

 

EX.NO: 3                                 EB BILL CALCULATION                                                   DATE:02.01.2025

 

Aim:

Write a program to prepare EB Bill Calculation

Source Code import java.util.Scanner; public class EBbill 

{     public static void main(String[] args) 

{

        int units;         double billToPay = 0;

 

        Scanner sc = new Scanner(System.in);

        System.out.println("Enter the number of units for calculating the electricity bill:");         units = sc.nextInt();

 

        if (units < 100) {

            billToPay = units * 1.20;         } else if (units < 300) {

            billToPay = 100 * 1.20 + (units - 100) * 2;

        } else if (units >= 300) {

            billToPay = 100 * 1.20 + 200 * 2 + (units - 300) * 3;

        }


 

        System.out.println("The electricity bill for " + units + " units is: $" + billToPay);

    }

}

 

Output

 

 

 

 

Result

The above Program has been Completed Successfully

 

 

 

 


                 4                                           FACTORIAL                             DATE:03.01.2025

Aim

Write a program to find the factorial value of the given number Source Code

 

import java.io.*; public class

Factorial1

{

 

public static void main(String args[])throws IOException

 

{

 

int n,i,fact=1;

 

BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

System.out.println("Enter the number:"); n=Integer.parseInt(br.readLine()); for(i=1;i<=n;i++)

{

 

fact=fact*i;

 

}

 

System.out.println("Factorial value:"+fact);

 

}

}

 

Output

 

 

 

 

Result

The above Program has been Completed Successfully

 

EX.NO: 5                                 MULTIPLICATION TABLE                                                DATE:09.01.2025

 

Aim

Write a Program to print Multiplication Table

Source Code

import java.io.*; public class Multable {     public static void main(String[] args)throws IOException 

{ int num;

BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); 

System.out.println("Enter the number:"); num=Integer.parseInt(br.readLine());

for (int i = 1; i <= 10; ++i)

{

System.out.printf("%d * %d = %d%n", num, i, num * i);

        }

    }

}

 

Output


 

 

 

 

 

Result

The above Program has been Completed Successfully

 

 

 

 

                 6                                FIBONACCI SERIES GENERATION  DATE:10.01.2025

Aim

Write a Program to print Fibonacci series

Source Code

import java.io.*;  public class Fibo

{ public static void main(String args[])throws IOException

{

BufferedReader br=new BufferedReader(new InputStreamReader (System.in));

String s; int n,i,f1=-1,f2=1,f3=0;

System.out.println("Enter the n values"); s=br.readLine(); n=Integer.parseInt(s);

System.out.println (" Fibonacci series:"); for(i=0; i<=n; i++)

{ f3=f1+f2;

System.out.println (f3); f1=f2; f2=f3;

}

}

} Output 

 

 

 

 

Result

The above Program has been Completed Successfully


                 7                                 PRIME OR NOT                                   DATE:20.01.2025

Aim

Write a Program to find the given number is prime or not 

Source Code import java.util.Scanner;

public class PrimeN {

 

  public static void main(String[] args) {

 

Scanner sc = new Scanner(System.in);         System.out.print("Enter the number: ");         long num = sc.nextLong();

 

    boolean flag = false;     for (int i = 2; i <= num / 2; ++i) {       // condition for nonprime number       if (num % i == 0) {         flag = true;         break;

      }     }

     if (!flag)

      System.out.println(num + " is a prime number.");     else

      System.out.println(num + " is not a prime number.");

  }

}

 

Output

 

 

 

Result

The above Program has been Completed Successfully

 

                 8                                 PERFECT OR NOT                              DATE:21.01.2025

Aim

Write a Program to find the given number is perfect or not

Source Code import java.util.Scanner; public class PerfectN{

    // Function to check if the given number is perfect or not     static long isPerfect(long num) {         long sum = 0;         for (int i = 1; i <= num / 2; i++) {             if (num % i == 0) {                 sum += i; // Calculate the sum of factors

            }

        }

        return sum;

    }

 

    public static void main(String[] args) {         Scanner sc = new Scanner(System.in);         System.out.print("Enter the number: ");         long n = sc.nextLong();         long sumOfFactors = isPerfect(n);         if (sumOfFactors == n) {

            System.out.println(n + " is a perfect number.");

        } else {

            System.out.println(n + " is not a perfect number.");

        }

    }

}

 

Output

 

 

 

 

Result

The above Program has been Completed Successfully

 

 

                 9                                 ARMSTRONG OR NOT                        DATE:27.01.2025

Aim

Write a Program to find the given number is Armstrong or not Source Code

import java.io.*;  public class Armst

{

 

public static void main(String args[])throws IOException

 

{

 

BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String s; int n,a,q,r,res=0;

System.out.println("Enter the any number"); s=br.readLine(); n=Integer.parseInt(s); a=n; while(n>0)

{ q=n/10;

r=n%10; res=res+(r*r*r);

n=q; } if(a==res)

System.out.println("This is an amstrong number"); else

System.out.println("This is not an amstrong number");

}

}

 

Output

 

 


                    0                               REVERSE THE DIGIT                         DATE:28.01.2025

Aim

Write a program to Reverse the Given number

Source Code

import java.io.*;  public class Revers

{

public static void main(String args[])throws IOException {

BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

String s;

int res, num,sum=0;

System.out.println("enter the number"); s=br.readLine(); num=Integer.parseInt(s);

System.out.println("enter the number to be reversed"); while(num>0)

{

 

res=num%10; sum=sum*10+res; num=num/10;

}

 

System.out.println(sum);

}

}

 

Output 

 

 

Result

The above Program has been Completed Successfully

 

 

 

 

 

 

                   1                               SUM OF DIGITS                                   DATE:03.02.2025

 

Aim

Write a program to find the Sum of Digits

Source Code import java.util.Scanner; public class sumofdigit{

    public static void main(String[] args) {         int number, digit, sum = 0;

        Scanner sc = new Scanner(System.in);         System.out.print("Enter the number: ");         number = sc.nextInt();         while (number > 0) {

            // Find the last digit of the given number             digit = number % 10; // 12%10=2             // Add the last digit to the variable 'sum'             sum += digit;//0+2=2

            // Remove the last digit from the number             number /= 10;//number=1

        }

        System.out.println("Sum of Digits: " + sum);

    }

}

 

Output 

 

 

 

Result

The above Program has been Completed Successfully

 

 

 

 

 

 

 

 

 

 

 

                    2                               DESCENDING ORDER                         DATE:04.02.2025

Aim

Write a java program to arrange the given numbers in descending order. Source Code

import java.io.*; class descend

{

public static void main(String args[])throws IOException {

BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int i,j,n,a[];

System.out.println("enter the number of elements to sort"); n=Integer.parseInt(br.readLine()); a=new int[100];

System.out.println("list it");

for(i=0;i<n;i++)

{

a[i]=Integer.parseInt(br.readLine());

}

for(i=0;i<n;i++)

{

for(j=i+i;j<n;j++)

{ int temp;  if(a[i]<a[j]) 

{ temp=a[i]; a[i]=a[j]; a[j]=temp;

}

}

}

System.out.println("after sorting"); for(i=0;i<n;i++)

{

System.out.println(a[i]);

}

}

}

 

 

 

 

 

 


Output 

 

 

 

 

 

Result

The above Program has been Completed Successfully

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

EX.NO: 13                               MATRIX ADDITION                                                           DATE:10.02.2025

 

Aim

Write program for Matrix Addition

Source Code import java.util.Scanner; class AddMatrix

{

public static void main(String args[])

{

int row, col,i,j;

Scanner in = new Scanner(System.in);

System.out.println("Enter the number of rows"); row = in.nextInt();

System.out.println("Enter the number columns"); col = in.nextInt(); int mat1[][] = new int[row][col]; int mat2[][] = new int[row][col]; int res[][] = new int[row][col];

System.out.println("Enter the elements of matrix1"); for ( i= 0 ; i < row ; i++ )


for ( j= 0 ; j < col ;j++ ) mat1[i][j] = in.nextInt();

System.out.println();

}

System.out.println("Enter the elements of matrix2"); for ( i= 0 ; i < row ; i++ )

{ for ( j= 0 ; j < col ;j++ )

mat2[i][j] = in.nextInt();

 

System.out.println();

} for ( i= 0 ; i < row ; i++ ) for ( j= 0 ; j < col ;j++ )

res[i][j] = mat1[i][j] + mat2[i][j] ;  System.out.println("Sum of matrices:-"); for ( i= 0 ; i < row ; i++ )

{  for ( j= 0 ; j < col ;j++ )

System.out.print(res[i][j]+"\t");

System.out.println();

}

}

}

Output 

 

 

 

 

Result

The above Program has been Completed Successfully

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 


                    4                               MATRIX SUBTRACTION                                                   DATE:12.02.2025

Write program for Matrix Subtraction

Source Code import java.util.Scanner;

 

class SubMatrix

{    public static void main(String args[])

   {

      int row, col,i,j;

      Scanner in = new Scanner(System.in);

 

      System.out.println("Enter the number of rows");       row = in.nextInt();

     

      System.out.println("Enter the number  columns");       col  = in.nextInt();

    

      int mat1[][] = new int[row][col];       int mat2[][] = new int[row][col];

      int res[][] = new int[row][col];

 

      System.out.println("Enter the elements of matrix1");

 

      for (  i= 0 ; i < row ; i++ )

       {   

    

            for ( j= 0 ; j < col ;j++ )

            mat1[i][j] = in.nextInt();

            

       }

      System.out.println("Enter the elements of  matrix2");

 

 

      for (  i= 0 ; i < row ; i++ )

       {

               

                  for ( j= 0 ; j < col ;j++ )                   mat2[i][j] = in.nextInt();         

      }

 

      for (  i= 0 ; i < row ; i++ )          for ( j= 0 ; j < col ;j++ )

             res[i][j] =  mat1[i][j]-mat2[i][j];   

 

      System.out.println("subtract  of  two matrices:-");

 

      for ( i= 0;i < row ;i++ )

       {  

                for ( j= 0 ; j < col ;j++ )

                System.out.print(res[i][j]+"\t");

             

         System.out.println();

       }  

   }

}

 

Output 

 

 

 

 

Result

The above Program has been Completed Successfully

 

 

 

 

 

 

 

 

 

 

 

 

 

 

                    5                               STRING HANDLING FUNCTION                                      DATE:18.02.2025

Write a program to perform the string operations using String class

Source Code

import java.util.Scanner; class Strings {   public static void main(String[] args) {         Scanner scanner = new Scanner(System.in);

        System.out.print("Enter a First string: ");

       String first = scanner.nextLine();     System.out.println("First String: " + first);

System.out.print("Enter a Second string: ");

     String second = scanner.nextLine();

    System.out.println("Second String: " + second);

     String joinedString = first.concat(second);

    System.out.println("Joined String: " + joinedString);

    System.out.print("Enter a more than one word: ");

String str1 = scanner.nextLine();

    System.out.println(str1.substring(0,10));   }

}

 

Output 

 

 

 

Result

The above Program has been Completed Successfully

             


                    6                               PALINDROME OR NOT                      DATE:19.02.2025

Write a java program to find the given string is palindrome or not.

Source Code

import java.io.*; import java.lang.*; import java.util.*; public class Palindrome

{

public static void main(String args[])throws IOException

{

BufferedReader s=new BufferedReader(new

InputStreamReader(System.in));

System.out.println("Enter the string you want to check:");

String myString=s.readLine();

StringBuffer buffer=new StringBuffer(myString); buffer.reverse();

String data=buffer.toString(); if(myString.equals(data))

{

System.out.println("given string is palindrome");

} else

{

System.out.println("given string is not palindrome");

}

}

}

 

Output 

 

 

 

 

Result

The above Program has been Completed Successfully

 

 

 

 

 

 

                    7                               STRING SORTING                               DATE:25.02.2025

Write a program to arrange the String an Ascending order.

Source Code

import java.util.Arrays;

import java.util.Scanner;

 

public class ascend17

{     public static String sortString(String inputString) 

{         char[] tempArray = inputString.toCharArray();         Arrays.sort(tempArray);         return new String(tempArray);

    }

 

    public static void main(String[] args) {

Scanner scanner = new Scanner(System.in);

        System.out.print("Enter a First string: "); String inputString = scanner.nextLine();

String outputString = sortString(inputString);

 

        System.out.println("Input String: " + inputString);

        System.out.println("Output String: " + outputString);

    }

}

 

Output 

 

 

 

Result

The above Program has been Completed Successfully

 

 

 

 

 

 

EX.NO: 18        FIND AVERAGE USING COMMAND LINE ARGUMENT  DATE:26.02.2025

 

 

 Aim

 

 Write a java program to accept n integers as command line arguments and find average 

 

Source Code

 

public class MyClass {     public static void main(String args[]) {

    

    int sum = 0;

     

    for(int i=0;i<args.length;i++)

    {

        sum +=Integer.parseInt(args[i]);

    }

 

    int average = sum / args.length;

    

    System.out.println("Average of " + args.length + " command line arguments is " + average);

    }


}

 

Output 

 

 

 

 

Result

The above Program has been Completed Successfully

 

 

 

 

 

 

 


EX.NO: 19       SUM OF MATRIX ITEMS IN ROWS AND COLUMNS                                                       DATE:04.03.2025

 

Aim 

Write a program to find the Sum of each Row in the given matrix Source Code public class Sum1 {

             

            public static void main(String[] args) {

                         

                        int i, j, rowsum, columnsum; 

             

                        int[][] Colsarr = {{11, 21, 31}, {41, 51, 61}, {71, 81, 91}};

                                        

                        for(i = 0; i < Colsarr.length; i++)

                        {

                                    rowsum = 0;                  columnsum = 0;

                                    for(j = 0; j < Colsarr[0].length; j++)

                                    {

                                                rowsum = rowsum + Colsarr[i][j];

                                                columnsum = columnsum + Colsarr[j][i];

                                    }


                                    System.out.println("\nThe Sum of Matrix Items "

                                                            + "in Row " + i + " = " + rowsum);

                                    System.out.println("\nThe Sum of Matrix Items "

                                                            + "in Column " + i + " = " + columnsum);

                        }

            }

}

 

Output 

 

 

 

Result

The above Program has been Completed Successfully

 

EX.NO: 20                                           CALCULATOR                         DATE:05.03.2025

 Aim 

Write a Java program that works as a simple calculator. Use a grid layout to arrange buttons for the digits and for the +, -,*, % operations. Add a text field to display the result. Handle any possible exceptions like divide by zero. Source Code import java.awt.*; import java.awt.event.*;

public class MyCalculator extends Frame implements ActionListener {     double num1,num2,result;

    Label lbl1,lbl2,lbl3;

    TextField tf1,tf2,tf3;     Button btn1,btn2,btn3,btn4;

    char op;     MyCalculator() {         lbl1=new Label("Number 1: ");

        lbl1.setBounds(50,100,100,30);

        

        tf1=new TextField();

        tf1.setBounds(160,100,100,30);

        

        lbl2=new Label("Number 2: ");

        lbl2.setBounds(50,170,100,30);

        

        tf2=new TextField();

        tf2.setBounds(160,170,100,30);

        

        btn1=new Button("+");

        btn1.setBounds(50,250,40,40);

 

        btn2=new Button("-");         btn2.setBounds(120,250,40,40);

 

        btn3=new Button("*");         btn3.setBounds(190,250,40,40);

 

        btn4=new Button("/");         btn4.setBounds(260,250,40,40);

        

        lbl3=new Label("Result : ");

        lbl3.setBounds(50,320,100,30);

        

        tf3=new TextField();

        tf3.setBounds(160,320,100,30);

 

        btn1.addActionListener(this);

        btn2.addActionListener(this);         btn3.addActionListener(this);         btn4.addActionListener(this);

        

        add(lbl1); add(lbl2); add(lbl3);         add(tf1);  add(tf2);  add(tf3);

        add(btn1); add(btn2); add(btn3); add(btn4);

 

        setSize(400,500);         setLayout(null);         setTitle("Calculator");

        setVisible(true);

        

    }

    

    public void actionPerformed(ActionEvent ae) {

        

        num1 = Double.parseDouble(tf1.getText());         num2 = Double.parseDouble(tf2.getText());

        

        if(ae.getSource() == btn1)

        {

            result = num1 + num2;

            tf3.setText(String.valueOf(result));

        }

        if(ae.getSource() == btn2)

        {

            result = num1 - num2;

            tf3.setText(String.valueOf(result));

        }

        if(ae.getSource() == btn3)

        {

            result = num1 * num2;

            tf3.setText(String.valueOf(result));

        }

        if(ae.getSource() == btn4)

        {

                result = num1 / num2;

                tf3.setText(String.valueOf(result));

        }     }

 

    public static void main(String args[]) {

        MyCalculator calc=new MyCalculator();

    }

}

 

 

 

 

 

 

 

Output 

 

 

 

Result

The above Program has been Completed Successfully

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

EX.NO: 21                                           SINGLE INHERITANCE          DATE:11.03.2025

 

Aim

Write a program using Single Inheritance.

Source Code

 

class Room

{ int Length, Breadth;

Room (int x, int y)

{

Length=x;

Breadth=y;

} int area () {

return (Length*Breadth);

}

}

class Room1 extends Room

{ int height;


Room1 (int x, int y, int z)

{

int volume ()

{

return (Length*Breadth*Height);

} }

class inhert

{

public static void main (String args[])

{

Room1 obj=new Room1(14,12,10);

int area1=obj.area (); int volume1=obj.volume();

System.out.println(“Area1 =”+area1);

System.out.println(“Volume =”+volume1);

}

}

 

 

 

 

 

 

Output 

 

 

 

Result

The above Program has been Completed Successfully

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

EX.NO: 22                                           HUMAN FACE                          DATE:18.03.2025

 

Aim 

Draw a Human Face using Applet

Source Code

import java.applet.*; 

import java.awt.*;  import java.lang.*;

/*<applet code=Face.class width=400 height=400></applet>*/  public class Face extends Applet

{

public void paint(Graphics g)

{

g.drawOval(40,40,120,150); 

g.drawOval(57,75,30,20); 

g.drawOval(110,75,30,20);

 g.fillOval(68,81,10,10);

 g.fillOval(121,81,10,10);

 g.drawOval(85,100,30,30); 

g.fillArc(60,120,75,40,180,180);


g.drawOval(25,92,15,30); 

g.drawOval(160,92,15,30);

}

 

}

 

Output 

 

 

 

Result

The above Program has been Completed Successfully

EX.NO: 23                                           NATIONAL FLAG                    DATE:19.03.2025

 

 

Aim  

Draw a national Flag using java applet 

Source Code import java.awt.*; import java.applet.*;

/*<applet code=Flags.class width=400 height=400></applet>*/ public class Flags extends Applet

{

public void paint(Graphics g)

{

g.fillOval(60,450,120,50);

g.fillOval(110,60,10,400);

g.setColor(Color.orange);

g.fillRect(120,80,150,30);

g.setColor(Color.white);

g.fillRect(120,110,150,30);

g.setColor(Color.green);


g.fillRect(120,140,150,30);

g.setColor(Color.blue);

g.drawOval(180,110,30,30); int t=0,x=195,y=125,n=24; double x1,y1,d,r=15; for(int i=0;i<=n;i++)

{

d=(double)t*3.14/180.0; x1=x+(double)r*Math.sin(d); y1=y+(double)r*Math.cos(d);

g.drawLine(x,y,(int)x1,(int)y1);

t+=360/24;

}

}

}

 

 

 

 

 

 

 

Output 

 

 

 

 

Result

The above Program has been Completed Successfully

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

EX.NO: 24                                           BAR CHART                             DATE:19.03.2025

 

import java.awt.*; import java.applet.*;

public class BarChart extends Applet

{ int n=0; String label []; int value []; public void init()

{ try {


n=integer.parsInt (getParameter(“columns”)); label=new String[n]; value = new int [n]; label[0]=getParameter (“label1”); label[1]=getParameter (“label2”); label[2]=getParameter (“label3); label[3]=getParameter (“label4”); value [0] =Integer.parseInt (getParameter (“c1”)); value [1] =Integer.parseInt (getParameter (“c2”)); value [2] =Integer.parseInt (getParameter (“c3”)); value [3] =Integer.parseInt (getParameter (“c4”));

}

catch (NumberFormatException e)

{

} }

public void paint (Graphics g)

{

for ( int i=0;i<n;i++)

{

g.setcolor(color.red);

g.drawstring(label [i],20,i*50+30); Year 1991 1992 1993 1994

 

Turnover(Rs Crores) 110 150 100 170

 

g.fillRect(50,i*50+10, value [i],40);

}

}

}

<html>

<applet

Code = BarChart.class

Width = 300

Height = 250>

<PARAM NAME = “columns” VALUE = “4”>

<PARAM NAME = “c1” VALUE =”110”>

<PARAM NAME = “c2” VALUE =”150”>

<PARAM NAME = “c3” VALUE =”100”>

<PARAM NAME = “c4” VALUE =”170”>

<PARAM NAME = “label1” VALUE =”91”>

<PARAM NAME = “label2” VALUE =”92”>

<PARAM NAME = “label3” VALUE =”93”>

<PARAM NAME = “label4” VALUE =”94”>

</applet> </html>

 

Output 

 

 

Result

The above Program has been Completed Successfully

  

 

Result

The above Program has been Completed Successfully

 


Comments

Popular posts from this blog

DBMS LAB

AIM: To write a sql program in ddl commands. PROGRAM: SQL> create table student(stid number, stname varchar(15), staddr varchar(15), stmob number(15)); Table created. SQL> desc student; Name Null? Type ----------------------------- -------- ------------------------ STID NUMBER STNAME VARCHAR2(15) STADDR VARCHAR2(15) STMOB NUMBER(15) SQL> alter table student add stmark number; Table altered. SQL> desc student; Name Null? Type --------------------------------- -------- -------------------- STID NUMBER STNAME VARCHAR2(15) STADDR VARCHAR2(15) STMOB NUMBER(15) STMARK NUMBER SQL> alter table student rename to student_info; Table altered. SQL> desc student; ERROR: ORA-04043: object student does not exist SQL> desc student_info; Name Null? Type -------------------------------- -------- ---------------- STID NUMBER STNAME VARCHAR2(15) STADDR VARCHAR2(15) STMOB NUMBER(15) STMARK NUMBER SQL> drop table student_info; Table dropped. SQL> desc student_info; ERROR: ORA-04...

Iwd only 8 pdf 😉(👈 click seiyavum)

 demonstrate the calculator program. Program : <html> <body> <script> const operator = prompt('Enter operator to perfome the calculation(either+,-,* or/):');  const number1 = parseFloat(prompt('Enter the first number:'));  const number2 = parseFloat(prompt('Enter the second number:'));  let result;  if(operator =='+') { result = number1+number2; } else if(operator =='-') { result = number1-number2; } else if(operator =='*') { result = number1*number2; } else { result=number1/number2; } window.alert("Result is"+result); </script> </body> </html> OUTPUT : Result : The given program is executed successfully. Ex no : 2 Date : FACTORIAL Aim: To demonstrate the factorial program. Program : <html> <body style="text align:center;font-size:20px;"> <h1>welcome to department of BCA</h1> <h1>FACTORIAL NUMBER</h1> enter the num...