Posts

Showing posts from July, 2025

JAVA RECORD PROGRAM TO CHECK PRIME OR NOT

 class Prime {   public static void main(String[] args) {     int num = 29;     boolean flag = false;     // 0 and 1 are not prime numbers     if (num == 0 || num == 1) {         flag = true;     }     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.");   } }

JAVA RECORD PROGRAM TO FIND BIGGEST OF THREE NUMBERS

 class Biggest {   public static void main (String[]args)   {    int num1 = 10, num2 = 20, num3 = 30;     if (num1 >= num2 && num1 >= num3)         System.out.println (num1 + " is the greatest");    else if (num2 >= num1 && num2 >= num3)         System.out.println (num2 + " is the greatest");     else if (num3 >= num1 && num3 >= num2)         System.out.println (num3 + " is the greatest");   } }

JAVA RECORD PROGRAM TO UNDERSTAND HYBRID INHERITANCE

 // Parent class class Animal {     void eat() {         System.out.println("Animal is eating");     } } // Child class inheriting from Animal class Dog extends Animal {     void bark() {         System.out.println("Dog is barking");     } } // Sub-child class inheriting from Dog class Labrador extends Dog {     void display() {         System.out.println("Labrador is a type of Dog");     } } public class Main {     public static void main(String[] args) {         Labrador labrador = new Labrador();         labrador.eat();   // Inherited from Animal         labrador.bark();  // Inherited from Dog         labrador.display();  // Defined in Labrador class     } }

JAVA RECORD PROGRAM TO UNDERSTAND MULTILEVL INHERITANCE

// Parent class class Animal {     void eat() {         System.out.println("Animal is eating");     } } // Child class inheriting from Animal class Dog extends Animal {     void bark() {         System.out.println("Dog is barking");     } } // Sub-child class inheriting from Dog class Labrador extends Dog {     void display() {         System.out.println("Labrador is a type of Dog");     } } public class Main {     public static void main(String[] args) {         Labrador labrador = new Labrador();         labrador.eat();   // Inherited from Animal         labrador.bark();  // Inherited from Dog         labrador.display();  // Defined in Labrador class     } }  

JAVA PROGRAM TO UNDERSTAND SINGLE INHERITANCE

 // Understanding Single Inheritance class Animal {     void eat() {         System.out.println("Animal is eating");     } } class Dog extends Animal {     void bark() {         System.out.println("Dog is barking");     } } public class Main {     public static void main(String[] args) {         Dog myDog = new Dog();                  myDog.eat();          myDog.bark();     } }

JAVA RECORD PROGRAM TO SORT STRINGS IN ALPHABETICAL ORDER

 // Java Program to Sort Names in an Alphabetical Order import java.io.*; class StringSort {     public static void main(String[] args)     {         int n = 4;         String names[]             = { "Java", "Python", "Oracle", "AI" };         String temp;         for (int i = 0; i < n; i++) {             for (int j = i + 1; j < n; j++) {                 if (names[i].compareTo(names[j]) > 0)                      {                     temp = names[i];                     names[i] = names[j];                     names[j] = temp;           ...

JAVA RECORD PROGRAM TO UNDERSTAND METHOD OVERLOADING

 class Sum {  int sum(int x, int y)      { return (x + y);   }   int sum(int x, int y, int z)     {        return (x + y + z);    }   double sum(double x, double y)     {        return (x + y);    } }   class Overload {  public static void main(String args[])     {         Sum s = new Sum();         System.out.println(s.sum(10, 20));         System.out.println(s.sum(10, 20, 30));         System.out.println(s.sum(10.5, 20.5));     } }

JAVA RECORD PROGRAM FOR AREA AND PERIMETER OF RECTANGLE

 // Java program to calculate  the area and perimeter of a rectangle using class concept import java.util.*; // Rectangle Class File class Rectangle {     // data members     int length, width;     // methods     //constructor to create Object     Rectangle(int length, int width) {         this. length = length;         this.width = width;     }     // prints the area of rectangle     public void area() {         int areaOfRectangle;         areaOfRectangle = this.length * this.width;         System.out.println("Area of rectangle with the given input is : " + areaOfRectangle);     }     // prints the perimeter of rectangle     public void perimeter() {         int  perimeterOfRectangle;         perimeterOfRectangle = 2 * (this...

JAVA RECORD PROGRAM FOR MATRIX MULTIPLICATION

 public class Example {    public static void main(String args[]) {       int n = 3;       int[][] a = { {5, 2, 3}, {2, 6, 3}, {6, 9, 1} };       int[][] b = { {2, 7, 5}, {1, 4, 3}, {1, 2, 1} };       int[][] c = new int[n][n];       System.out.println("Matrix A:");       for (int i = 0; i < n; i++) {          for (int j = 0; j < n; j++) {             System.out.print(a[i][j] + " ");          }          System.out.println();       }       System.out.println("Matrix B:");       for (int i = 0; i < n; i++) {          for (int j = 0; j < n; j++) {             System.out.print(b[i][j] + " ");          }          System.out.pr...

JAVA RECORD PROGRAM FOR FIBBONACCI SERIES

import java.io .*; public class FibonacciSeries {   public static void main(String args[]) {     int a, b, c, i, n;     n = 10;     a = b = 1;     System.out.print (a + " " + b);     for (i = 1; i <= n - 2; i++) {       c = a + b;       System.out.print (" ");       System.out.print (c);       a = b;       b = c;     }   } }