0% found this document useful (0 votes)
35 views37 pages

Arindam 12

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)
35 views37 pages

Arindam 12

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/ 37

Name – Arindam Pal

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

Question-1: An Armstrong number is such that


the sum of the cube of the digits of the
number is the number itself.
Example:153=13+53+33.
Design a class Armstrong to perform the given
task. Some of the number of the class given
below:
Class Name-Armstrong
Data member/Instance variable:-
Construct=Armstrong(nn)
void sumofdigit:To verify and print whether
the number is in an Armstrong number or not
int isArmstrong(n):-Verify and return the
value.

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:

Variable name Data type Purpose in the


program
n int To store integer
value.
nn int To accept integer
value from user.
l int To store integer
value.
num int To accept integer
value from user.
s String To store a String
variable.
i int To accept integer
value from user.

OUTPUT:

P age |8
Date-16/05/2024

Question-2: Write a program to check whether a


number is Bouncy number or not?
Bouncy number: A positive integer that is neither in
increasing nor decreasing number is called Bouncy
number. In other words, a number whose digits are
unsorted.
Increasing number: In an integer traversing from left
to right if the current digit is greater than or equal
to the previous digit, the number is known as
increasing number. Example: 23689
Decreasing number: In an integer traversing from
left to right if the current digit is less than the
previous digit the number is known as decreasing
number. Example: 98632
Example of Bouncy number: 13174, 101, 15296

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:

Variable name Data type Purpose in the


program
num int To accept integer
value from user.
x boolean To store Boolean
value as true or false
in program.
n int To store integer
value.
x int To store integer
value from user.
isdecreasing boolean To return value as
true or false in
program.
isincreasing boolean To return value as
true or false in
program.
temp int To store integer
value in the program.
prev int To store integer
value in the program.
rem int To store integer
value in the program.

P a g e | 14
OUTPUT:

P a g e | 15
Date-27/06/2024

Question-3: Write a java program to declare a matrix


a[][] of order (m*n) where m is the number of rows
and n is the number of columns such that the values of
both m and n must be greater than 2 and less than 10.
Allow the user to input integers into the matrix,
perform the following task on the matrix:
a) Display the original matrix
b) Sort each row of the matrix in ascending order
using any standard sorting technique.
c) Display the changed matrix after sorting each row.
Example:
5 -2 3 -2 3 5
4 10 2 => 2 4 10
8 13 -3 -3 8 13

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

Question-4: An (n*n) matrix is called a positive


Markov matrix. If each element is positive and the sum
of the elements is positive and the sum of the elements in
each row is 1. Write the following function to check
whether a matrix is Markov matrix or not.
class name: Markov
const int size=n
size not greater than 3 or less than 2
boolean is Markov=true
boolean is negative=false
Write a program that user enter a (n*n) matrix of
double values and test whether it is a Markov
matrix or not.

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.

col double To store double


value in the
program.

P a g e | 26
OUTPUT:

P a g e | 27
Date-12/07/2024

Question-5: Write a program to declare a matrix a[][]


of order (m*n) where m is row number and n is column
number, such that m and n not greater than 10 and less
than 2. Accept the value of m and n by user input.
Display an appropriate message for invalid input. Allow
the user to input integer into matrix. Perform the
following tasks.
a) Display the original matrix
b) Rotate the matrix 270o anticlockwise as shown
below.
1234 951
5678 => 862
9807 073
784

P a g e | 28
ALGORITHM:
Step 1: Start

Step 2: Initialize 2D array where m and n is row


and column.

Step 3: Create an empty array where m is column and n is

row.

Step 4: Take one variable q & set the value (m-1).

Step 5: By using outer loop decrease the value of q.

Step 6: By using inner loop increase the value of p.

Step 7: Copy all the elements values from a to b according

to the condition.

Step 8: Display using inner loop and outer loop.

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.

x int To store integer


value in the
program.

P a g e | 32
OUTPUT:

P a g e | 33
Date-19/07/2024

Question-6: Write a program to declare a square


matrix M[][] of order ‘N’ where N must be greater than 3
and less than 10. Allow the user to accept three different
characters from the keyboard and fill the array according
to the instruction given below:
a) Fill the four corners of the square by the
characters 1.
b) Fill the boundary elements of the matrix (except the
four corners) by character 2.
c) Fill the non-boundary elements of the matrix by
character 3.
Example:
Input: Output:
N =4 @ ? ? @
Character 1=@ ? # # ?
Character 2=? ? # # ?
Character 3=# @ ? ? @

P a g e | 34
ALGORITHM:

Step 1: Start

Step 2: Initialize 2D array where n is row and


column.

Step 3: Accept three characters from user.

Step 4: Check the four corner elements and replace it with


character 1.

Step 5: Check the boundary elements and replace it with


character 2.

Step 6: Check the non-boundary elements and replace it


with character 3.

Step 7: After replacing print the array.

Step 8: Display using inner loop and outer loop.

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

You might also like