0% found this document useful (0 votes)
6 views3 pages

Comp and Bio

Uploaded by

kntanay09
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views3 pages

Comp and Bio

Uploaded by

kntanay09
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

HW Programs on Array

Program to take 2-D array as an argument and print the output as given below

1 2 3 4

3 5

7 9

4 6 7 8
public class holSqMat

static void main(int n[][])

int r,c;

if(n.length==n[0].length)

System.out.println("Modified Matrix");

for(r=0;r<n.length;r++)

for(c=0;c<n[0].length;c++)

if(r==0||r==n.length-1||c==0||c==n[0].length-1)

System.out.print(n[r][c]+" ");

else

System.out.print(" "+" ");

System.out.println();

A program to read 10 employee names and sort in Ascending Order Buble and Selection sort

Note : Write 2 different programs for Buble and Selection sort

PGM – Selection Sort


1

import java.util.*;
Page
public class AsSelSort

public static void main()

Scanner sc=new Scanner(System.in);

int n[]=new int[10];

int i,j;

System.out.println("Enter 10 employee code");

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

n[i]=sc.nextInt();

int small,pos,temp;

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

small=n[i];

pos=i;

for( j=i+1;j<n.length;j++)

if(n[ j]<small)

small=n[ j];

pos=j;

temp=n[i];

n[i]=n[pos];

n[pos]=temp;

System.out.println("Sorted Array - Employee name in Ascending order");

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

System.out.print(n[i]+" ");
2
Page

}
System.out.println();

PGM – Buble Sort


import java.util.*;

public class bubSort

static void main()

Scanner sc=new Scanner(System.in);

int n[]=new int[10];

System.out.println("Enter 10 Employee code");

int i,j,temp;

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

n[i]=sc.nextInt();

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

for( j=0;j<n.length-1-i;j++)

if(n[ j]>n[ j+1])

temp=n[ j];

n[ j]=n[ j+1];

n[ j+1]=temp;

System.out.println("Sorted array");

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

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

}
3
Page

You might also like