Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
16 views

Assi 6 Java

The document contains two Java programs, one that sorts integers in ascending order using bubble sort, and another that demonstrates 2D arrays by adding two 3x3 matrices and outputting the result.

Uploaded by

PRATIKSHA BHOYAR
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

Assi 6 Java

The document contains two Java programs, one that sorts integers in ascending order using bubble sort, and another that demonstrates 2D arrays by adding two 3x3 matrices and outputting the result.

Uploaded by

PRATIKSHA BHOYAR
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Assignment No.

6
/* Write a program for accepting 10 integer Numbers and sort them in
ascending order using bubble sort */
import java.lang.*;
import java.util.Scanner;
public class Sortdemo
{
public static void main(String[]args)
{
Scanner sc=new Scanner(System.in);
int lim;
System.out.println("Enter how many element you want to enter:");
lim=sc.nextInt();
int list[]=new int[lim];
System.out.println("Enter the elements to be sorted:");
for(int i=0;i<list.length;i++)
{
list[i]=sc.nextInt();
}
for(int i=0;i<list.length;i++)
{
for(int j=i+1;j<list.length;j++)
{
if(list[i]>list[j])
{
int t=list[i];
list[i]=list[j];
list[j]=t;
}
}
}
System.out.println("The array element to be sorted as follows");
for(int i=0;i<list.length;i++)
{
System.out.println(list[i]);
}
}
}

Output:
Assignment No. 7

Write a java program to demonstrate 2D array by finding Addition of Two 3*3


Matrices.

import java.util.Scanner;
public class AddMatrix
{
public static void main(String[]args)
{
int i,j;
int m1[][]=new int[3][3];
int m2[][]=new int[3][3];
int m3[][]=new int[3][3];
Scanner s=new Scanner(System.in);
System.out.println("Enter Matrix1 elements:");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
m1[i][j]=s.nextInt();
}
}
System.out.println("Enter Matrix2 elements:");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
m2[i][j]=s.nextInt();
}
}
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
m3[i][j]=m1[i][j] + m2[i][j];
}
}
System.out.println("Addition of two given matrix is:\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
System.out.print(m3[i][j]+" ");
}
System.out.println();
}

}
}

Output:

You might also like