Skip to main content

Posts

Showing posts with the label Java Programming

Write a java program for multiplying two matrices and print the product for the same | VCMIT

Two matrices and print the product for the same. INPUT public class Matrix1{ public static void main(String args[]){    int a[][]={{1,1,1},{2,2,2},{3,3,3}};  int b[][]={{1,1,1},{2,2,2},{3,3,3}};      int c[][]=new int[3][3];    for(int i=0;i<3;i++){  for(int j=0;j<3;j++){  c[i][j]=0;    for(int k=0;k<3;k++)    {    c[i][j]+=a[i][k]*b[k][j];    } System.out.print(c[i][j]+" ");  } System.out.println();  }  }} OUTPUT

Write a java program to add two matrices and print the resultant matrix | VCMIT

Add two matrices and print the resultant matrix. INPUT public class Matrix{ public static void main(String args[]){  int a[][]={{1,3,4},{2,4,3},{3,4,5}};  int b[][]={{1,3,4},{2,4,3},{1,2,4}};    int c[][]=new int[3][3];    for(int i=0;i<3;i++){  for(int j=0;j<3;j++){  c[i][j]=a[i][j]+b[i][j];  System.out.print(c[i][j]+" ");  }  System.out.println();  }  }} OUTPUT

Write a java program to implement multiple inheritance | VCMIT

Multiple Inheritance. INPUT interface Car {     int speed=60;     public void distanceTravelled(); } interface Bus {     int distance=100;     public void speed(); } public class Vehicle implements Car,Bus {     int distanceTravelled;     int averageSpeed;     public void distanceTravelled()     {         distanceTravelled=speed*distance;         System.out.println("Total Distance Travelled is : "+distanceTravelled);     }     public void speed()     {         int averageSpeed=distanceTravelled/speed;         System.out.println("Average Speed maintained is : "+averageSpeed);     }     public static void main(String args[])     {         Vehicle v1=new Vehicle();         v1.distanceTravelled();         v1.speed...

Write a java program to implement method overriding | VCMIT

Method Overriding INPUT class Human{      public void eat()    {       System.out.println("Human is eating");    } } class Boy extends Human{      public void eat(){       System.out.println("Boy is eating");    }    public static void main( String args[]) {       Boy obj = new Boy();           obj.eat();    } } OUTPUT

Write a java program to implement single level inheritance. | VCMIT

Single Level Inheritance.  INPUT class Single{  static int num1=10;  static int num2=5; } class Main extends Single{  public static void main(String[] args){  int num3=2;  int result=num1+num2+num3;  System.out.println("Result of child class is "+result);  } } OUTPUT

Write a java program to demonstrate the implementation of abstract class. | VCMIT

Implementation of Abstract Class. INPUT import java.util.Scanner; abstract class test { abstract void get(); } class test1 extends test { void get() { int a,b; Scanner ob=new Scanner(System.in); System.out.print("Enter 1st Number: "); a=ob.nextInt(); System.out.println("Enter 2st Number: "); b=ob.nextInt(); System.out.println("Addition is: "+(a+b)); } } class prac4C { public static void main(String args[]) { test1 obj=new test1(); obj.get(); } } OUTPUT

Designed a class that demonstrates the use of constructor and destructor. | VCMIT

Constructor And Destructor. INPUT class Square{ int width,height; Square( int a , int b){ width = a; height = b; } int area(){ return width * height; } } class Cal{ public static void main(String[] args){ { Square s1 = new Square(10,20); int area_of_sqaure = s1.area(); System.out.println("The area of square is:" + area_of_sqaure); } } } OUTPUT

Designed a class SortData that contains the method asec() and desc(). | VCMIT

The Method asec() And desc(). INPUT import java.util.*; class prac4A { Scanner input=new Scanner(System.in); int num,i; int arr[]; int temp=0; public void getdata() { System.out.print("Enter the size of array: "); num=input.nextInt(); arr=new int[num]; System.out.print("Enter the number: "); for( i=0;i<num;i++) { arr[i]=input.nextInt(); } } void putdata() { System.out.print("Given numbers are: "); for(i=0;i<num;i++) { System.out.println(arr[i]); } } void asce() { for(i=0;i<num;i++) { for(int j=i+1;j<num;j++) { if(arr[i]>arr[j]) { temp=arr[i]; arr[i]=arr[j]; arr[j]=temp; } } } System.out.print("Ascending order of number are: "); for(int i=0;i<num;i++) { System.out.println(arr[i]); } } void desc() { for(i=0;i<num;i++) { for(int j=i+1;j<num;j++) { if(arr[i]<arr[j]) { temp=arr[i]; arr[i]=arr[j]; arr[j]=temp; } } } System.out.print("Descending order of number are: "); for(int i=0;i<num;i++) { System.out.println(...