Arindam 12
Arindam 12
Class - XI
Sec - A
Roll No. - 32
Subject – Computer Assignment
Year - 2024-2025
P age |1
P age |2
P age |3
Date-9/05/2024
P age |4
ALGORITHM:
Step 1: Start
Step 2: Declare the class Armstrong with a public modifier
Step 3: To start the program open the main function.
Step 4: Declare the integer variable num, length, n, nn,
member function sum
Step 5: Create a object of same class ob
Step 6: Taking a parameterized constructor to calculate
the length of digit. Convert number into string by using
Integer.toString method and find the length of string by
length function and save it in length.variable.
Step 7: By using void sumofdigit function check the sum of
power of digit is equal to the give number. Then return the
value in int isArmstrong(n) method.
Step 8: Taking the integer i<0. If it satisfy the condition,
then return the value int void sumofdigit() function. Else
finding the modulus of the number and passing the value
to int isArmstrong(n) function to verify again.
Step 9: End
P age |5
PROGRAM:
import java.util.*;
public class Armstrong
{
int n,nn,l;
public static void main()
{
int num;
System.out.println("Enter the number");
Scanner sc=new Scanner(System.in);
num=sc.nextInt();
Armstrong ob=new Armstrong(num);
ob.sumofdigit();
}
public Armstrong(int nn)
{
n=nn;
String s=Integer.toString(n);
l=s.length();
}
public int isArmstrong(int i)
{
P age |6
if(i<10)
{
return (int)Math.pow(i,l);
}
else
{
return isArmstrong (i/10)+ isArmstrong(i%10);
}
}
void sumofdigit()
{
if(n==isArmstrong(n))
System.out.println("The number is Armstrong
number");
else
System.out.println("The number is not an
Armstrong number");
}
}
P age |7
VARIABLE DESCRIPTION:
OUTPUT:
P age |8
Date-16/05/2024
P age |9
ALGORITHM:
Step 1: Start
Step 2: Import the java.util.Scanner class to read input
from the user.
Step 3: Create a scanner object to take the input number from
the user and store that input in an integer num.
Step 4: We call the isBouncy() function which if it return true,
print that the input number is “is a bouncy number”.
Step 5: Define the isBouncy() method. In this function we
initialize two Boolean fag, isincreasing and isdecreasing as true.
Step 6: Check if all the digit of the given number are in
ascending order or not. Run a loop and check if any digit is
greater than the next digit. If any digit is greater than the next
digit then set the isincreasing flag as false.
Step 7: Repeat the previous step but this time we check for
decreasing order and set the isdecreasing flag as false.
Step 8: Check both the flag and the value is returned per the
condition.
Step 9: End
P a g e | 10
PROGRAM:
import java.util.*;
public class Bouncy
{
public static void main()
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the number: ");
int num=sc.nextInt();
Bouncy ob=new Bouncy(num);
ob.isBouncy(num);
boolean x=ob.isBouncy(num);
if(x==true)
{
System.out.println("The number is a Bouncy
Number");
}
else
{
System.out.println("The number is not a Bouncy
Number");
}
}
public Bouncy(int n)
{
P a g e | 11
int x=n;
}
static boolean isBouncy(int x)
{
boolean isdecreasing=true;
boolean isincreasing=true;
int temp=x;
int prev=temp%10;
while(temp>=0)
{
int rem=temp%10;
if(rem>prev)
{
isincreasing=false;
break;
}
else
{
prev=rem;
temp=temp/10;
}
}
while(temp>=0)
{
int rem=temp%10;
P a g e | 12
if(rem<prev)
{
isdecreasing=false;
break;
}
else
{
prev=rem;
temp=temp/10;
}
}
if(!isincreasing && !isdecreasing)
return true;
else
return false;
}
}
P a g e | 13
VARIABLE DESCRIPTION:
P a g e | 14
OUTPUT:
P a g e | 15
Date-27/06/2024
P a g e | 16
ALGORITHM:
Step 1: Start
Step 2: Import the java.util.Scanner class to read input
from the user.
Step 3: Create a scanner object to take the input number from
the user to store the number of rows and column and check if
the column and row is greater than 2 and less than 9.
Step 4: Enter the element of the array and display the array.
Step 5: Sort the columns of the array in ascending order using
swapping technique.
Step 6: Initialize a integer temp as a third variable for swapping.
Step 7: If a[i][k] greater than a[i][k+1] then first variable equal to
second variable ,then second equals to third variable and third
equals to first variable.
Step 8: Print the sorted array.
Step 9: End
P a g e | 17
PROGRAM:
import java.util.*;
class dda
{
public static void main (String args[])
{
Scanner sc= new Scanner(System.in);
System.out.println("Enter the number of column.");
int m= sc.nextInt();
System.out.println("Enter the number of row.");
int n= sc.nextInt();
if(m<2||m>9||n<2||n>9)
{
System.out.println("INVALID INPUT");
}
int a[][]= new int[m][n];
System.out.println("Enter the element in the 2D
array.");
for(int i=0;i<m;i++)
{
for(int j=0;j<n;j++)
{
a[i][j]=sc.nextInt();
}
}
P a g e | 18
System.out.println("The original 2D array.");
for(int i=0;i<m;i++)
{
for(int j=0;j<n;j++)
{
System.out.print(a[i][j]+" ");
}
System.out.println();
}
int temp;
for(int i=0;i<m;i++)
{
for(int j=0;j<n;j++)
{
for(int k=0;k<n-1-j;k++)
{
if(a[i][k]>a[i][k+1])
{
temp= a[i][k];
a[i][k]=a[i][k+1];
a[i][k+1]=temp;
}
}
}
}
P a g e | 19
System.out.println("The shorted 2D array.");
for(int i=0;i<m;i++)
{
for(int j=0;j<n;j++)
{
System.out.print(a[i][j]+" ");
}
System.out.println();
}
}
}
P a g e | 20
VARIABLE DESCRIPTION:
Variable name Data type Purpose in the
program
m int To accept integer
value from user.
n int To accept integer
value from user.
a[][] int To store integer
Value in array.
i int Initializer in the for
loop
j int Initializer in the for
loop
temp int To store integer
value in the program.
OUTPUT:
P a g e | 21
Date-05/07/2024
P a g e | 22
ALGORITHM:
Step 1: Start.
Step 2: Choose a size n for the matrix.
Step 3: Initialize a (n*n) matrix with all entries set to less than
one.
Step 4: For each row i:
Generate a random probability distribution (non-negative
numbers that sum to 1).
Step 5: For each row j:
Generate a random probability distribution (non-negative
numbers that sum to 1).
Step 6:. Normalize the matrix by dividing each entry by the sum
of row and column.
Step 7: If is Markov==true and is negative==false then print the
matrix with a print statement. “It is Markov matrix”.
Step 8: If not print the statement “It is not Markov matrix”.
Step 9: End
P a g e | 23
PROGRAM:
import java. util.*;
class markovarray
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter the number of row and column.");
int m=sc.nextInt();
if(m>3||m<2)
{
System.out.println("Invalid input");
}
double a[][]=new double[m][m];
boolean ismarkov=true;
System.out.println("Enter the element in the 2D array.");
for(int i=0;i<m;i++)
{
for(int j=0;j<m;j++)
{
a[i][j]=sc.nextDouble();
if(a[i][j]>1||a[i][j]<0)
{
System.out.println("Retry");
j--;
}
}
}
double row, col;
for(int i=0;i<a.length;i++)
{
P a g e | 24
row=0.0;
for(int j=0;j<a.length;j++)
{
row+=a[i][j];
}
if(row!=1 )
{
ismarkov= false;
}
}
for(int j=0;j<m;j++)
{
col=0.0;
for(int i=0;i<m;i++)
{
col+=a[j][i];
}
if(col!=1 )
{
ismarkov = false;
}
}
for(int i=0;i<m;i++)
{
for(int j=0;j<m;j++)
{
System.out.print(a[i][j]+" ");
}
System.out.println();
}
if(ismarkov==true)
{
P a g e | 25
System.out.println("It is a markov matrix.");
}
else
{
System.out.println("It is not a markov matrix.");
}
}
}
VARIABLE DESCRIPTION:
Variable name Data type Purpose in the
program
m int To accept integer
value from user.
a[][] double To accept double
type value in array.
ismarkov boolean To return Boolean
data type.
i int Initializer in the for
loop
j int Initializer in the for
loop
row double To store double
value in the program.
P a g e | 26
OUTPUT:
P a g e | 27
Date-12/07/2024
P a g e | 28
ALGORITHM:
Step 1: Start
row.
to the condition.
Step 9: End
P a g e | 29
PROGRAM:
import java.util.*;
public class twodmatrics
{
public static void main (String args[])
{
Scanner sc= new Scanner(System.in);
System.out.println("Enter the number of column: ");
int M= sc.nextInt();
System.out.println("Enter the number of row: ");
int N=sc.nextInt();
if(M<3||M>9 && N<3||N>9)
{
System.out.println("INVALID INPUT");
}
int a[][]= new int[M][N];
System.out.println("Enter the element in the 2D
array.");
for(int i=0;i<N;i++)
{
for(int j=0;j<M;j++)
{
a[i][j]=sc.nextInt();
}
}
P a g e | 30
System.out.println("The original 2D array.");
for(int i=0;i<N;i++)
{
for(int j=0;j<M;j++)
{
System.out.print(a[i][j]);
}
System.out.println();
}
int b[][]= new int[M][N];
int x;
for(int i=0;i<N;i++)
{
x=M-1;
for(int j=0;j<M;j++)
{
b[i][j]=a[x][i];
x--;
}
}
System.out.println("The rotated 2D array.");
for(int i=0;i<N;i++)
{
x=M-1;
for(int j=0;j<M;j++)
P a g e | 31
{
System.out.print(b[i][j]);
}
System.out.println();
}
}
}
VARIABLE DESCRIPTION:
Variable name Data type Purpose in the
program
M int To accept integer
value from user.
N int To accept integer
value from user.
a[][] int To store integer
value in array.
i int Initializer in the for
loop
j int Initializer in the for
loop
b[][] int To store integer
value in the array.
P a g e | 32
OUTPUT:
P a g e | 33
Date-19/07/2024
P a g e | 34
ALGORITHM:
Step 1: Start
Step 9: End
P a g e | 35
PROGRAM:
import java.util.*;
public class MatrixModifier
{
public static void main(String[] args)
{
Scanner sc= new Scanner(System.in);
System.out.println("Enter the number of the rows and column");
int n= sc.nextInt();
System.out.print("Enter character 1: ");
char ch1=sc.next().charAt(0);
System.out.print("Enter character 2: ");
char ch2=sc.next().charAt(0);
System.out.print("Enter character 3: ");
char ch3=sc.next().charAt(0);
if(n>10||n<3)
{
System.out.println("Invalid input");
}
char m[][] = new char[n][n];
for (int i=0;i<n;i++)
{
for (int j=0;j<n;j++)
{
if ((i == 0 && j == 0) || (i == 0 && j == n - 1) || (i == n - 1 && j == 0) || (i == n - 1
&& j == n - 1))
{
m[i][j]=ch1;
System.out.print(m[i][j]);
}
else if (i == 0 || i == n - 1 || j == 0 || j == n - 1)
{
m[i][j]=ch2;
System.out.print(m[i][j]);
} else
{
m[i][j]=ch3;
System.out.print(m[i][j]);
}
}
System.out.println();
}
}
}
P a g e | 36
VARIABLE DESCRIPTION:
Variable name Data type Purpose in the
program
n int To accept integer
value from user.
ch1 char To accept character
value from user.
ch2 char To accept character
value from user.
ch3 char To accept character
value from user.
m[][] char To store character
value in array.
i int Initializer in the for
loop.
j int Initializer in the for
loop.
OUTPUT:
P a g e | 37