Java Array

Bubble Sort Java Program

Bubble sort in java is the simplest sorting technique. In bubble sort algorithm each element is compared to next adjacent element, if the next element is smaller, then it will be swapped by previous element. Although this technique is simple but it is too slow as compared to other sorting techniques. Below I have shared …

Bubble Sort Java Program Read More »

Java Program for Multiplication of two Matrices

import java.util.Scanner; //import Scanner class in our program class demo { public static void main(String…s) { int i,j,m,n,p,q,k; Scanner sc=new Scanner(System.in); //used to read from keyboard System.out.print(“Enter number of rows and columns of first matrix:”); m=sc.nextInt(); n=sc.nextInt(); System.out.print(“Enter number of rows and columns of second matrix:”); p=sc.nextInt(); q=sc.nextInt(); if(n!=p) System.out.print(“nSorry multiplication can’t be done!!”); else …

Java Program for Multiplication of two Matrices Read More »

Java Program for Addition of two Matrices

import java.util.Scanner; //import Scanner class in our program class demo { public static void main(String…s) { int i,j,n,m; Scanner sc=new Scanner(System.in); //used to read from keyboard System.out.print(“Enter number of rows:”); m=sc.nextInt(); System.out.print(“Enter number of columns:”); n=sc.nextInt(); int a1[][]=new int[m][n]; int a2[][]=new int[m][n]; int a3[][]=new int[m][n]; System.out.print(“nEnter elements of first matrix:n”); for(i=0;i<m;++i) for(j=0;j<n;++j) a1[i][j]=sc.nextInt(); System.out.print(“nEnter elements …

Java Program for Addition of two Matrices Read More »

Java Program to Find Smallest and Largest Element in an Array

import java.util.Scanner; //import Scanner class in our program class demo { public static void main(String…s) { int i,n,large,small; Scanner sc=new Scanner(System.in); //used to read from keyboard System.out.print(“Enter number of elements:”); n=sc.nextInt(); int a[]=new int[n]; System.out.print(“nEnter elements of Array:”); for(i=0;i<n;++i) a[i]=sc.nextInt(); large=small=a[0]; for(i=1;i<n;++i) { if(a[i]>large) large=a[i]; if(a[i]<small) small=a[i]; } System.out.print(“nSmallest Element:”+small); System.out.println(“nLargest Element:”+large); } }