Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions MatrixMultiply.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import java.util.*;
public class MatrixMultiply{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the number of rows of matrix A: ");
int n1 = sc.nextInt();
System.out.println("Enter the number of columns of matrix A: ");
int m1 = sc.nextInt();
System.out.println("Enter the number of rows of matrix B: ");
int n2 = sc.nextInt();
System.out.println("Enter the number of columns of matrix B: ");
int m2 = sc.nextInt();
int[][] A = new int[n1][m1];
int[][] B = new int[n2][m2];
if(m1!=n2){
System.out.println("Matrix A and Matrix B are not of same size");
System.exit(0);
}
for(int i=0;i<n1;i++){
for(int j=0;j<m1;j++){
System.out.println("Enter the value of A["+i+"]["+j+"]: ");
A[i][j] = sc.nextInt();
System.out.println();
}
System.out.println();
}
for(int i=0;i<n2;i++){
for(int j=0;j<m2;j++){
System.out.println("Enter the value of B["+i+"]["+j+"]: ");
B[i][j] = sc.nextInt();
System.out.println();
}
System.out.println();
}
sc.close();
int[][] C = new int[n1][m2];
for(int i=0;i<n1;i++){
for(int j=0;j<m2;j++){
for(int k=0;k<m1;k++){
C[i][j] += A[i][k] * B[k][j];
}
}
System.out.println();
}
for(int i=0;i<n1;i++){
for(int j=0;j<m2;j++){
System.out.print(C[i][j]+" ");
}
System.out.println();
}
}
}
1 change: 1 addition & 0 deletions Primenumber.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ public static void main(String args[])
Scanner sc=new Scanner(System.in);
System.out.println("Enter a no.:");
int n=sc.nextInt();
sc.close();
int i,c=0;
for(i=1;i<=n;i++)
{
Expand Down
25 changes: 25 additions & 0 deletions RangedPrime.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import java.util.*;
public class RangedPrime{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the lower bound of the range: ");
int l = sc.nextInt();
System.out.println("Enter the upper bound of the range: ");
int u = sc.nextInt();
sc.close();
System.out.println("Prime numbers between " + l + " and " + u);
for (int i = l; i <= u; i++) {
if (isPrime(i)) {
System.out.println(i);
}
}
}
static boolean isPrime(int prime) {
for (int i = 2; i <= Math.sqrt(prime); i++) {
if (prime % i == 0) {
return false;
}
}
return true;
}
}