EX.NO:1
PRIME NUMBERS
PROGRAM:
public class PrimeNumbers
{
public static void main(String[]args)
{
int num=20;
int count;
for(int i=1; i<=num; i++)
{
count=0;
for(int j=2; j<=i/2; j++)
{
if(i%j==0)
{
count++;
break;
}
}
if(count==0)
{
System.out.println(i);
}
}
}
}
OUTPUT:
1
2
3
5
7
11
13
17
19
EX.NO:2
MATRIX MULTIPLICATION
PROGRAM:
public class MultiplyMatrices
{
public static void main(String[]args)
{
int r1=2, c1=3;
int r2=3, c2=2;
int[][] firstMatrix = { {3, -2, 5}, {3, 0, 4} };
int[][] secondMatrix= { {2, 3}, {-9,0}, {0, 4} };
int[][] product=new int[r1][c2];
for(int i=0; i<r1; i++)
, {
for(int j=0; j<c2; j++)
{
for(int k=0; k<c1; k++)
{
product[i][j]+=firstMatrix[i][k]*secondMatrix[k][j];
}
}
}
System.out.println("Multiplication of two matrice is: ");
for(int[] row:product)
{
for(int column:row)
{
System.out.print(column+" ");
}
System.out.println();
}
}
}
OUTPUT:
Multiplication of two matrice is:
24 29
6 25
EX.NO:3
TEXT ANALYZER
PROGRAM:
import java.util.Scanner;
public class TextAnalyzer
{
public static void main(String[]args)
{
Scanner s=new Scanner(System.in);
System.out.println();
int charCount=0;
int wordCount=0;
int lineCount=0;
while(true)
{
String line=s.nextLine();
if(line.equalsIgnoreCase("exit"))
{
break;
}
lineCount++;
charCount+=line.length();
String[]words=line.split("\\s+");
wordCount+=words.length;
System.out.println("TextAnalyzer");
System.out.println("Total characters:"+charCount);
System.out.println("Total words:"+wordCount);
PRIME NUMBERS
PROGRAM:
public class PrimeNumbers
{
public static void main(String[]args)
{
int num=20;
int count;
for(int i=1; i<=num; i++)
{
count=0;
for(int j=2; j<=i/2; j++)
{
if(i%j==0)
{
count++;
break;
}
}
if(count==0)
{
System.out.println(i);
}
}
}
}
OUTPUT:
1
2
3
5
7
11
13
17
19
EX.NO:2
MATRIX MULTIPLICATION
PROGRAM:
public class MultiplyMatrices
{
public static void main(String[]args)
{
int r1=2, c1=3;
int r2=3, c2=2;
int[][] firstMatrix = { {3, -2, 5}, {3, 0, 4} };
int[][] secondMatrix= { {2, 3}, {-9,0}, {0, 4} };
int[][] product=new int[r1][c2];
for(int i=0; i<r1; i++)
, {
for(int j=0; j<c2; j++)
{
for(int k=0; k<c1; k++)
{
product[i][j]+=firstMatrix[i][k]*secondMatrix[k][j];
}
}
}
System.out.println("Multiplication of two matrice is: ");
for(int[] row:product)
{
for(int column:row)
{
System.out.print(column+" ");
}
System.out.println();
}
}
}
OUTPUT:
Multiplication of two matrice is:
24 29
6 25
EX.NO:3
TEXT ANALYZER
PROGRAM:
import java.util.Scanner;
public class TextAnalyzer
{
public static void main(String[]args)
{
Scanner s=new Scanner(System.in);
System.out.println();
int charCount=0;
int wordCount=0;
int lineCount=0;
while(true)
{
String line=s.nextLine();
if(line.equalsIgnoreCase("exit"))
{
break;
}
lineCount++;
charCount+=line.length();
String[]words=line.split("\\s+");
wordCount+=words.length;
System.out.println("TextAnalyzer");
System.out.println("Total characters:"+charCount);
System.out.println("Total words:"+wordCount);