Computer Isc 11
Computer Isc 11
ISC 2024 - 25
NAME : DHRUV MANSHANI
CLASS AND SECTION : XI - CA
ID : 4691
SUBMITTED TO : MRS. NEHA
THOMBRE
TABLE OF CONTENTS
An Evil number is a positive whole number which has even number of 1's in its binary equivalent.
Example: Binary equivalent of 9 is 1001, which contains even number of 1's. A few evil numbers are 3, 5,
6, 9…. Design a program to accept a positive whole number and find the binary equivalent of the number
and count the number of 1's in it and display whether it is a Evil number or not with an appropriate
message. Output the result in format given below:
Example 1
Input: 15
Binary Equivalent: 1111
No. of 1's: 4
Output: Evil Number
Example 2
Input: 26
Binary Equivalent: 11010
No. of 1's: 3
Output: Not an Evil Number
ALGORITHM :
Step 1 : Declaring Scanner class
Step 2 : Take Input and store it in the variable n
Step 3 : Converting n into it’s binary equivalent
Step 4 : Counting the number of 1s and deciding if it’s evil or not
Step 5 : Displaying output
Step 6 : Stop
CODING :
import java.util.*;
class As1{
void main(){
//Declaring Scanner Class
Scanner sc = new Scanner(System.in);
//taking input
System.out.println("Enter no.");
int n = sc.nextInt();
int s = 0;
String t ="";
int count = 0;
//Displaying output
System.out.println("Binary Equivalent = "+t);
System.out.println("No. of 1s = "+count);
if(count%2==0)
System.out.println("Evil Number");
else
System.out.println("Not an Evil Number");
}
}
OUTPUT :
VDT :
ALGORITHM :
Step 1 : Taking input of m and n
Step 2 : checking for composite number in the given range
Step 3 : Checking for magic number in the given range
Step 4 : Displaying all the composite magic numbers
Step 5 : Displaying the frequency of the composite magic numbers
Step 6 : Stop
CODING :
import java.util.*;
class As2{
void main(){
//declaring scanner class
Scanner sc = new Scanner(System.in);
//taking input of m and n
System.out.println("Enter m");
int m = sc.nextInt();
System.out.println("Enter n");
int n = sc.nextInt();
int compmagic_count = 0;
for(int j = i;j>0;j/=10){
tsum += j%10;
}
while(tsum>9){
int tsum1 = tsum;
tsum = 0;
for(int f = tsum1;f>0;f/=10){
tsum += f%10;
}
//displaying composite magic numbers
if(tsum==1){
System.out.print(i+" ");
compmagic_count++;
}
}
//displaying frequency of composite magic numbers
System.out.println();
System.out.println("Frequency of Composite Magic Numbers is "+compmagic_count);
}else
System.out.println("Invalid Input");
}
}
OUTPUT :
VDT :
ALGORITHM :
Step 1 : Create an array will all alphabets.
Step 2 : take input of the sentence
Step 3 : Check each alphabet with all the letters of the array
Step 4 : fill the matched letters with spaces in the array
Step 5 : If array is filled with spaces, it is panagram
Step 6 : Create a loop to check for the longest and shortest word
Step 7 ; Display Output
Step 8 : Stop
CODING :
import java.util.*;
class Panagram{
void main(){
Scanner sc = new Scanner(System.in);
//taking input
System.out.println("Enter Sentence");
String s = sc.nextLine();
if((s.charAt(s.length()-1)=='.')||(s.charAt(s.length()-1)=='?')||(s.charAt(s.length()-1)=='!')){
s = s.toLowerCase();
char a[] = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
StringTokenizer str = new StringTokenizer(s);
int count = str.countTokens();
String longest = "";
String shortest = "";
//checking if string is panagram
while(str.hasMoreTokens()){
String d = str.nextToken();
for(int i = 0;i<d.length();i++){
char ch = d.charAt(i);
for(int j = 0;j<26;j++){
if(a[j]==ch){
a[j] = ' ';
break;
}
}
}
//checking for longest and shortest word
if(d.length()>longest.length())
longest = d;
if(shortest == ""){
shortest = d;
continue;
}
if(d.length()<shortest.length())
shortest = d;
}
int p = 0;
for(int i = 0;i<26;i++){
if(a[i]!=' ')
p++;
}
//displaying output
if(p==0)
System.out.println("String is Panagram");
else
System.out.println("String is not Panagram");
System.out.println("Longest Word : "+longest);
System.out.println("Shortest Word : "+shortest);
}else
System.out.println("INVALID INPUT");//incase input is invalid
}}
OUTPUT :
VDT :
CODING :
import java.util.*;
class As4{
void main(){
Scanner sc = new Scanner(System.in);//declaring scanner class
//taking input
System.out.println("Enter a number");
int n = sc.nextInt();
int rn = 0;
int count = 0;
int t = n;
//counting the no. of digits
for(int j = n;j>0;j/=10){
count++;
}
//reversing the number
for(int i = count-1;i>=0;i--){
rn += (Math.pow(10,i)*(n%10));
n/=10;
}
//displaying output
if(rn==t)
System.out.println("Palindrone Number");
else
System.out.println("Not A Palindrone Number");
}}
OUTPUT :
VDT :
Variable/Array Name Data Type Purpose Scope
ASSIGNMENT 5
Problem Statement :
A Prime-Adam integer is a positive integer (without leading zeros) which is a prime as well as an Adam
number.
Prime number: A number which has only two factors, i.e. 1 and the number itself.
Example: 2, 3, 5, 7 … etc.
Adam number: The square of a number and the square of its reverse are reverse to each other.
Example: If n = 13 and reverse of 'n' = 31, then,
(13)2 = 169
(31)2 = 961 which is reverse of 169
thus 13, is an Adam number.
Accept two positive integers m and n, where m is less than n as user input. Display all Prime-Adam
integers that are in the range between m and n (both inclusive) and output them along with the frequency,
in the format given below:
Test your program with the following data and some random data:
Example 1
INPUT:
m=5
n = 100
OUTPUT:
THE PRIME-ADAM INTEGERS ARE:
11 13 31
FREQUENCY OF PRIME-ADAM INTEGERS IS: 3
Example 2
INPUT:
m = 100
n = 200
OUTPUT:
THE PRIME-ADAM INTEGERS ARE:
101 103 113
FREQUENCY OF PRIME-ADAM INTEGERS IS: 3
Example 3
INPUT:
m = 50
n = 70
OUTPUT:
THE PRIME-ADAM INTEGERS ARE:
NIL
FREQUENCY OF PRIME-ADAM INTEGERS IS: 0
Example 4
INPUT:
m = 700
n = 450
OUTPUT:
INVALID INPUT
ALGORITHM :
Step 1 : Take input of m and n
Step 2 : Check if m<n
Step 3 : Checking every number between the range if it prime
Step 4 : Checking every number between the range if it is adam
Step 5 : Displaying output
Step 6 : Stop
CODING :
import java.util.*;
class As5{
void main(){
//declaring scanner class
Scanner sc = new Scanner(System.in);
int adam_count = 0;
for(int j = k;j>0;j/=10){
count2++;
}
int t = k;
for(int i = count2-1;i>=0;i--){
rn += (Math.pow(10,i)*(t%10));
t/=10;
}
int square1 = k*k;
int squaret = square1;
int sqaurern = 0;
for(int j = square1;j>0;j/=10){
count3++;
}
for(int i = count3-1;i>=0;i--){
sqaurern += (Math.pow(10,i)*(squaret%10));
squaret/=10;
}
if(sqaurern==(rn*rn)){
System.out.print(k+" ");
adam_count++;
}
}
if(adam_count==0)
System.out.print("NIL");
System.out.println();
VDT :
Variable/Array Name Data Type Purpose Scope
ALGORITHM :
Step 1 : to take input and convert into uppercase
Step 2 : to find the frequency of vowels and consonants and display with an appropriate message
Step 3 : To rearrange the word as per given condition
Step 4 : to display to the original word and the rearranged word
Step 5 : to define a main function, create an object and call other methods
Step 6 : Stop
CODING :
import java.util.*;
class Rearrange{
String wrd, newwrd;
//default constructor
Rearrange(){
wrd = "";
newwrd = "";
void readword(){
//taking input
Scanner sc = new Scanner(System.in);
System.out.println("Enter word");
wrd = sc.next();
void freq_vow_con(){
int v = 0, c = 0;
//counting no. of vowels and consonants
for(int i = 0;i<wrd.length();i++){
char ch = wrd.charAt(i);
if((ch=='A')||(ch=='E')||(ch=='I')||(ch=='O')||(ch=='U')){
v++;
}else if((ch>=65)&&(ch<=97)){
c++;
}
}
System.out.println("Number of consonants = "+c);
System.out.println("Number of vowels = "+v);
void arrange(){
for(int i = 0;i<wrd.length();i++){
char ch = wrd.charAt(i);
if((ch=='A')||(ch=='E')||(ch=='I')||(ch=='O')||(ch=='U')){
newwrd +=ch;
}
}
for(int i = 0;i<wrd.length();i++){
char ch = wrd.charAt(i);
if((ch!='A')&&(ch!='E')&&(ch!='I')&&(ch!='O')&&(ch!='U')){
newwrd +=ch;
}
}
}
//displaying output
void display(){
System.out.println("Original Word = "+wrd);
System.out.println("Rearranged Word = "+newwrd);
void main(){
Rearrange a = new Rearrange();
a.readword();
a.freq_vow_con();
a.arrange();
a.display();
}
}
OUTPUT :
VDT :
ALGORITHM :
Step 1 : Create a default constructor
Step 2 : to accept word
Step 3 : convert uppercase alphabets to lowercase and vice - versa
Step 4 : display the original and the toggled word
Step 5 : to define a main function, create an object and call other methods
Step 6 : Stop
CODING :
import java.util.*;
class Toggle{
String str;
String newstr;
int len;
//deault constructor
Toggle(){
str = "";
newstr = "";
len = 0;
}
//taking input
void readword(){
Scanner sc = new Scanner(System.in);
System.out.println("Enter string");
str = sc.nextLine();
}
//toggling word
void toggle(){
for(int i = 0;i<str.length();i++){
char ch = str.charAt(i);
if(Character.isUpperCase(ch))
newstr += Character.toLowerCase(ch);
else
newstr +=Character.toUpperCase(ch);
}
}
//displaying output
void display(){
System.out.println("Original Word = "+str);
System.out.println("Toggled Word = "+newstr);
}
//main method
void main(){
Toggle a = new Toggle();
a.readword();
a.toggle();
a.display();
}
}
OUTPUT :
VDT :
ALGORITHM :
Step 1 : Create a default constructor
Step 2 : to accept original string and mask string and convert them to lowercase
Step 3 : to form a new string as per the given conditions
Step 4 : display the original and the newly formed string
Step 5 : to define a main function, create an object and call other methods
Step 6 : Stop
CODING :
import java.util.*;
class StringOp{
String str, msk, nstr;
//deault construtor
StringOp(){
str = "";
msk = "";
nstr = "";
}
//input
void accept(){
Scanner sc = new Scanner(System.in);
System.out.println("Enter String");
str = sc.nextLine();
System.out.println("Enter masked String");
msk = sc.nextLine();
str = str.toLowerCase();
msk = msk.toLowerCase();
for(int i = 0;i<str.length();i++){
char ch = str.charAt(i);
int temp = 0;
for(int j = 0;j<msk.length();j++){
char d = msk.charAt(j);
if(ch==d){
temp++;
break;
}
if(temp==0){
nstr +=ch;
}
}
}
//displaying output
void display(){
System.out.println("Original String"+str);
System.out.println("Output"+nstr);
}
//creating main method
void main(){
}
OUTPUT :
VDT :
ALGORITHM :
Step 1 : to take input
Step 2 : to convert the given input into uppercase
Step 3 : to check for vowels in pairs
Step 4 : to count the no. of such pairs
Step 5 : To display the pairs and their number
Step 6 : Stop
CODING :
import java.util.*;
class As9{
void main(){
Scanner sc = new Scanner(System.in);//declairng scanner class
//taking input
System.out.println("Enter String");
String s = sc.nextLine();
s = s.toUpperCase();//converting to uppercase
int sum = 0;
System.out.print("Pair of vowels: ");
//finding out pairs of vowels
for(int i = 0;i<s.length()-1;i++){
char ch = s.charAt(i);
char h = s.charAt(i+1);
if(((ch=='A')||(ch=='E')||(ch=='I')||(ch=='O')||(ch=='U'))&&((h=='A')||(h=='E')||(h=='I')||(h=='O')||(h=='U')))
{
System.out.print(ch+""+h+"\t");
sum++;
}
}
System.out.println();
System.out.println("No. of Pairs = "+sum);//displaying no. of pairs
}
}
OUTPUT :
VDT :
Write a program to declare a square matrix A[][] of order (M × M) where 'M' must be greater than 3 and
less than 10. Allow the user to input positive integers into this matrix. Perform the following tasks on the
matrix:
1. Sort the non-boundary elements in ascending order using any standard sorting technique and
rearrange them in the matrix.
2. Calculate the sum of both the diagonals.
3. Display the original matrix, rearranged matrix and only the diagonal elements of the rearranged
matrix with their sum.
Test your program for the following data and some random data
ALGORITHM :
Step 1 : taking input of size and then elements of array
Step 2 : displaying original matrix
Step 3 : Sorting the non boundary elements into a different array and then transferring them back
Step 4 : Displaying the rearranged matrix
Step 5 : Calculating sum of both the diagonals and then displaying it
Step 6 : Stop
CODING :
import java.util.*;
class As10{
void main(){
Scanner sc = new Scanner(System.in);
System.out.println("Enter the size of array");
int m = sc.nextInt();
if((m>3)&&(m<10)){
int a[][] = new int[m][m];
int temp[] = new int[(m-2)*(m-2)];
int temp1 = 0;
for(int i = 0;i<m;i++){//input
for(int j = 0;j<m;j++){
a[i][j] = sc.nextInt();
if((i!=0)&&(j!=m-1)&&(i!=m-1)&&(j!=0)){
temp[temp1] = a[i][j];
temp1++;
}
}
}
System.out.println("Original Matrix");
for(int i = 0;i<m;i++){//original matrix display
for(int j = 0;j<m;j++){
System.out.print(a[i][j]+" ");
}
System.out.println();
}
int tt = 0;
for(int i = 0;i<((m-2)*(m-2));i++){//sorting
for(int j= 0;j<((m-2)*(m-2))-i-1;j++){
if(temp[j]>temp[j+1]){
tt = temp[j];
temp[j] = temp[j+1];
temp[j+1] = tt;
}
}
}
temp1 = 0;
for(int i = 0;i<m;i++){//transfering sorted elements
for(int j = 0;j<m;j++){
if((i!=0)&&(j!=m-1)&&(i!=m-1)&&(j!=0)){
a[i][j] = temp[temp1];
temp1++;
}
}
}
System.out.println("Rearranged Matrix");
for(int i = 0;i<m;i++){//rearranged matrix display
for(int j = 0;j<m;j++){
System.out.print(a[i][j]+" ");
}
System.out.println();
}
int sum = 0;
for(int i = 0;i<m;i++){
for(int j = 0;j<m;j++){
if(i==j)
sum+=a[i][j];
else if(i+j==m-1)
sum+=a[i][j];
}
}
System.out.println("Diagonal Matrix");
for(int i = 0;i<m;i++){//diagonal matrix display
for(int j = 0;j<m;j++){
if((i==j)||(i+j==m-1)){
System.out.print(a[i][j]+" ");
}else
System.out.print(" ");
}
System.out.println();
}
System.out.println("Sum of diagonal = "+sum);
}else
System.out.println("Out of Range");
}
OUTPUT :
VDT :
Write a 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 this matrix. Perform the following tasks on the matrix:
ALGORITHM :
Step 6 : Stop
CODING :
import java.util.*;
class As11{
void main(){
int m = sc.nextInt();
int n = sc.nextInt();
if((m>2)&&(m<10)&&(n>2)&&(n<10)){
System.out.println("Enter elements");
for(int i = 0;i<m;i++){
for(int j = 0;j<n;j++){
a[i][j] = sc.nextInt();
System.out.println("Original Matrix");
for(int i = 0;i<m;i++){
for(int j = 0;j<n;j++){
System.out.print(a[i][j]+" ");
}
System.out.println();
//sorting
int temp = 0;
for(int i = 0;i<m;i++){
for(int k = 0;k<n;k++){
for(int j = 0;j<n-k-1;j++){
if(a[i][j]>a[i][j+1]){
temp = a[i][j];
a[i][j] = a[i][j+1];
a[i][j+1] = temp;
System.out.println("Rearranged Matrix");
for(int i = 0;i<m;i++){
for(int j = 0;j<n;j++){
System.out.print(a[i][j]+" ");
}
System.out.println();
}else{
System.out.println("Out of Range");
OUTPUT :
VDT :
Write a program to accept a sentence which may be terminated by either '.', '?' or '!' only. The words are to
be separated by a single blank space and are in UPPER CASE.
1. Check for the validity of the accepted sentence only for the terminating character.
2. Arrange the words in ascending order of their length. If two or more words have the same length,
then sort them alphabetically.
3. Display the original sentence along with the converted sentence.
Test your program for the following data and some random data
ALGORITHM :
Step 6 : Stop
CODING :
import java.util.*;
class As12{
void main(){
Scanner sc = new Scanner(System.in);//declaring scanner class
String s = sc.nextLine();
if((s.charAt(s.length()-1)=='.')||(s.charAt(s.length()-1)=='!')||(s.charAt(s.length()-1)=='?')){
s =s.substring(0,s.length()-1);
//arranging sentence
for(int i = 0;i<count;i++){
a[i] = str.nextToken();
for(int i = 0;i<count;i++){
for(int j = 0;j<count-i-1;j++){
if(a[j].length()==a[j+1].length()){
if(a[j].compareTo(a[j+1])>0){
temp = a[j];
a[j] = a[j+1];
a[j+1] = temp;
}else if(a[j].length()>a[j+1].length()){
temp = a[j];
a[j] = a[j+1];
a[j+1] = temp;
//displaying output
for(int i = 0;i<count;i++){
System.out.print(a[i]+" ");
}else
OUTPUT :
VDT :
Step 3 : finding the number of words starting and ending with a vowel
Step 4 : Placing the words starting and ending with a vowel at first and then placing the rest of the words
Step 6 : Stop
CODING :
import java.util.*;
class As13{
void main(){
String s = sc.nextLine();
s = s.toUpperCase();
if((s.charAt(s.length()-1)=='.')||(s.charAt(s.length()-1)=='!')||(s.charAt(s.length()-1)=='?')){
s = s.substring(0,s.length()-1);
String a = "";
while(str.hasMoreTokens()){
a = str.nextToken();
if(((a.charAt(0)=='A')||(a.charAt(0)=='E')||(a.charAt(0)=='I')||(a.charAt(0)=='O')||(a.charAt(0)=='U'))&&((
a.charAt(a.length()-1)=='A')||(a.charAt(a.length()-1)=='E')||(a.charAt(a.length()-1)=='I')||(a.charAt(a.lengt
h()-1)=='O')||(a.charAt(a.length()-1)=='U'))){
sum++;
}else
temp = temp.trim();
System.out.print(temp+".");
System.out.println();
}else
}
}
OUTPUT :
VDT :
CODING :
OUTPUT :
VDT :
CODING :
import java.util.*;
class As15{
void main(){
Scanner sc = new Scanner(System.in);//declaring scanner class
for(int j = n;j>1;){
for(int i = 2;i<=j;i++){
if(j%i==0){
a[temp] = i;
j/=i;
temp++;
break;
}
}
}
}
int p = 0;
System.out.print(n+" : ");
//checking for hamming number
for(int i = 0;i<temp;i++){
if(i==temp-1)
System.out.print(a[i]);
else
System.out.print(a[i]+" x ");
if(a[i]!=3&&a[i]!=2&&a[i]!=5)
p++;
}
//displaying output
System.out.println();
if(p==0)
System.out.println("Hamming Number");
else
System.out.println("Not A hamming Number");
}
}
OUTPUT :
VDT :
p int To check for factors other than 2,3 & 5 Global to main()
Accept two strings from the user and check if they are anagrams of each other. Ensure that the
comparison is case-insensitive and ignores spaces. Display an appropriate message based on
whether they are anagrams or not. If any of the strings contain invalid characters (e.g., numbers
or special characters), generate an error message.
Test your program with the following data and some random data:
Example 1
INPUT:
Example 2
INPUT:
Enter first string: Dormitory
Enter second string: Dirty room
OUTPUT:
Example 3
INPUT:
OUTPUT :
INVALID CHARACTERS IN STRING. INVALID INPUT
ALGORITHM :
Step 1 : taking input for two strings and converting it to lowercase
Step 2 : Checking for invalid characters in the string
Step 3 : Comparing all the characters of the strings with each other by adding one’s to the array
Step 4 : Filling with spaces the matched characters
Step 5 : Displaying appropriate message in case the whole array is filled with spaces or not
Step 6 : Stop
CODING :
import java.util.*;
class As16{
void main(){
s1 = s1.toLowerCase();
s2 = s2.toLowerCase();
int t = 0;
//checking for invalid characters
for(int i = 0;i<s1.length();i++){
if(s1.charAt(i)==' ')
continue;
int ch = s1.charAt(i);
if((ch>=65&&ch<=91)||(ch>=97&&ch<=123)){
}else{
t++;
break;
}
}
if(t==0){
//checking if strings are anagram
for(int i = 0;i<s1.length();i++){
char ch = s1.charAt(i);
a[i] = ch;
}
for(int i = 0;i<s2.length();i++){
char ch = s2.charAt(i);
for(int j = 0;j<s1.length();j++){
if(ch==a[j]){
a[j] = ' ';
break;
}
}
}
int p = 0;
for(int i = 0;i<a.length;i++){
if(a[i]!=' '){
p++;
}
}
//displaying Output
if(p>0){
System.out.println("Strings are not Anagram");
}else
System.out.println("Strings are Anagram");
}else
System.out.println("Invalid characters in string. Invalid Input");
}
}
OUTPUT :
VDT :
Variable Data Type Purpose Scope
Name
CODING :
import java.util.*;
class As17{
void main(){
//declaring scanner class
Scanner sc = new Scanner(System.in);
int sd = 0;
for(int i = 0;i<m;i++){
for(int j = 0;j<n;j++){
if(a[i][j]%2!=0)
sd+=a[i][j];
}
}
System.out.println("Sum of Odd elements : "+sd);
}else
System.out.println("Size out of range");
}
}
OUTPUT :
VDT :
Variable Data Type Purpose Scope
Name
CODING :
import java.util.*;
class ArmNum{
int n;
int l;
//parameterized constructor
ArmNum(int nn){
n = nn;
l = 0;
}
int sum_pow(){
//to count the number of digits
for(int i = n;i>0;i/=10){
l++;
}
int sum = 0;
for(int i = n;i>0;i/=10){
sum+= Math.pow((i%10),l);
}
}
}
OUTPUT :
VDT :
sum int To store the sum of digits raised to power l Local to for()
ALGORITHM :
Step 1 : Declaring variables and making a parameterized constructor
Step 2 : finding out the sum of digits
Step 3 : finding out the product of digits
Step 4 : checking if number is spy
Step 5 : Displaying output
Step 6 : Stop
CODING :
import java.util.*;
class Spy{
int num;
//parameterized constructor
Spy(int nn){
num = nn;
}
//Sum of Digits
int sumOfDigits(int i){
if (i==0)
return 0;
else
return (i%10+sumOfDigits(i/10));
}
//Product of Digits
int prodOfDigits(int i){
if(i==0)
return 1;
else
return (i%10*prodOfDigits(i/10));
}
}
//declaring main method and calling other methods
void main(){
Spy a = new Spy(242);
a.sumOfDigits(num);
a.prodOfDigits(num);
a.check();
}
}
OUTPUT :
VDT :
Variable Data Type Purpose Scope
Name
CODING :
import java.util.*;
class Unique{
//declaring variables
String word;
int len;
Unique(){
word = "";
len = 0;
}
//accepting input
void accept(){
System.out.println("Enter word");
Scanner sc = new Scanner(System.in);
word = sc.next();
word = word.toUpperCase();
len = word.length();
}
//checking if word is unique
boolean checkUnique(){
if(((word.charAt(0)=='A')||(word.charAt(0)=='E')||(word.charAt(0)=='I')||(word.charAt(0)=='O')||(word.ch
arAt(0)=='U'))&&((word.charAt(len-1)=='A')||(word.charAt(len-1)=='E')||(word.charAt(len-1)=='I')||(wor
d.charAt(len-1)=='O')||(word.charAt(len-1)=='U')))
return true;
else
return false;
}
//displaying output
void display(){
System.out.println("The word is "+word);
if(checkUnique())
System.out.println("It is a Unique word");
else
System.out.println("It is not a Unique word");
}
//main method to call other methods
void main(){
Unique a = new Unique();
a.accept();
a.checkUnique();
a.display();
}
}
OUTPUT :
VDT :
CODING :
import java.util.*;
class As21{
void main(){
Scanner sc = new Scanner(System.in);
System.out.println("Enter M");
int M = sc.nextInt();
System.out.println("Enter N");
int N = sc.nextInt();
if((M>2)&&(N>2)&&(M<10)&&(N<10)){
//taking input
System.out.println("Enter elements");
for(int i = 0;i<M;i++){
for(int j = 0;j<N;j++){
A[i][j] = sc.nextInt();
}
}
for(int i = 0;i<M;i++){
for(int j = 0;j<N;j++){
if(i==M-1){
System.out.print(A[0][j]+" ");
continue;
}
System.out.print(A[i+1][j]+" ");
}
System.out.println();
}
//finding out the highest element
int temp = A[0][0];
int ii = 0,jj = 0;
for(int i = 0;i<M;i++){
for(int j = 0;j<N;j++){
if(temp<A[i][j]){
temp = A[i][j];
ii = i;
jj = j;
}
}
}
//displaying highest element
System.out.print("Highest element = "+temp);
System.out.println(" (Row: "+ii+" Column: "+jj+")");
}else
System.out.println("SIZE OUT OF RANGE. INVALID ENTRY");
}
}
OUTPUT :
VDT :
Test your program for the following data and some random data:
Example 1 :
Example 2 :
ALGORITHM :
Step 1 : to take input of size and elements
Step 2 : To display the original matrix
Step 3 : to find whether the matrix is symmetric
Step 4 : To find the sum of left and right diagonal
Step 5 : To display whether the matrix is symmetric or not and display the sum of diagonals
Step 6 : Stop
CODING :
import java.util.*;
class As22{
void main(){
//declaring scanner class
Scanner sc = new Scanner(System.in);
System.out.println("Enter M");
int M = sc.nextInt();
if((M>2)&&(M<10)){
//taking input
System.out.println("Enter elements");
for(int i = 0;i<M;i++){
for(int j = 0;j<M;j++){
A[i][j] = sc.nextInt();
}
}
//Displaying Original Matrix
System.out.println("Original Matrix");
for(int i = 0;i<M;i++){
for(int j = 0;j<M;j++){
System.out.print(A[i][j]+" ");
}
System.out.println();
}
//Checking if A[][] is symmetric or not
int p = 0;
for(int i = 0;i<M;i++){
for(int j = 0;j<M;j++){
if(A[i][j]!=A[j][i])
p++;
}
}
if(p>0)
System.out.println("The Given Matrix is not Symmetric");
else
System.out.println("The Given Matrix is Symmetric");
if(i+j==M-1)
sum2 += A[i][j];
}
}
//displaying sum of right & left diagonal
System.out.println("Sum of Right Diagonal: "+sum1);
System.out.println("Sum of Left Diagonal: "+sum2);
}else
System.out.println("SIZE OUT OF RANGE. INVALID ENTRY");
}
}
OUTPUT :
VDT :
A[][] int To store the elements input by the user Global to main()
1. 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:
(ii) Fill the boundary elements of the matrix (except the four corners) by character 2.
Test your program with the following data and some random data:
Example 1:
INPUT: N = 4
FIRST CHARACTER: @
SECOND CHARACTER: ?
THIRD CHARACTER: #
OUTPUT:
@??@
?##?
?##?
@??@
Example 2: INPUT: N = 5
FIRST CHARACTER: A
SECOND CHARACTER: C
THIRD CHARACTER: X
OUTPUT:
ACCCA
CXXXC
CXXXC
CXXXC
ACCCA
Example 3: INPUT: N = 15
ALGORITHM :
Step 1 : to take input of the size of the array and the three characters
Step 2 : To check the input size for validity
Step 3 : To declare the array as per the size entered
Step 4 : to fill the array with the three characters entered by the user
Step 5 : To display the output array
Step 6 : Stop
CODING :
import java.util.*;
class As23{
void main(){
//declaring scanner class
Scanner sc = new Scanner(System.in);
//input for rows and columns
System.out.println("Enter the value of n");
int n = sc.nextInt();
if((n>3)&&(n<10)){
char m[][] = new char[n][n];//declaring array
//input for characters
System.out.println("Enter Character one");
char c1 = sc.next().charAt(0);
System.out.println("Enter Character two");
char c2 = sc.next().charAt(0);
System.out.println("Enter Character three");
char c3 = sc.next().charAt(0);
//alloting characters
for(int i = 0;i<n;i++){
for(int j = 0;j<n;j++){
if((i==0&&j==0)||(i==n-1&&j==n-1)||(i==0&&j==n-1)||(i==n-1&&j==0))
m[i][j] = c1;
else if(i==0||j==0||i==n-1||j==n-1)
m[i][j] = c2;
else
m[i][j] = c3;
}
}
//displaying output
for(int i = 0;i<n;i++){
for(int j = 0;j<n;j++){
System.out.print(m[i][j]+" ");
}
System.out.println();
}
}else
System.out.println("Size Out Of Range");
}
}
OUTPUT :
VDT:
Variable Data Type Purpose Scope
Name
class As24{
void main(){
//declaring scanner class
Scanner sc = new Scanner(System.in);
System.out.println("Enter the value of n");
int n = sc.nextInt();
//declaring array which will store input
double m[][] = new double[n][n];
if((n>=3)||(n<=9)){
int neg = 0;
//taking input
System.out.println("Enter elements");
for(int i = 0;i<n;i++){
for(int j= 0;j<n;j++){
m[i][j] = sc.nextDouble();
if(m[i][j]<0)
neg++;
}}
//check for doubly markov matrix
if(neg==0){
int ex1 = 0,ex2 = 0;
double sumr = 0, sumc = 0;
for(int i = 0;i<n;i++){
for(int j = 0;j<n;j++){
sumr+=m[i][j];
}
if(sumr!=1){
ex1++;
break;
}
sumr = 0;
}
for(int j = 0;j<n;j++){
for(int i = 0;i<n;i++){
sumc +=m[i][j];
}
if(sumc!=1){
ex2++;
break;
}
sumc = 0;
}
//displaying output
if((ex1>0)||(ex2>0))
System.out.println("Not a Doubly Markov Matrix");
else
System.out.println("Doubly Markov Matrix");
}
if(neg>0)
System.out.println("Not A Doubly Markov Matrix");
}else
System.out.println("Out of Bounds");
}
}
OUTPUT :
VDT :
ALGORITHM :
Step 1 : To declare variables and initializing them with a parameterized constructor
Step 2 : To create methods Check() for checking whether a no. is automorphic or not
Step 3 : To create method list() to find out the list of automorphic numbers between l and u and display
them.
Step 4 : To count and display the frequency of automorphic numbers
Step 5 : to create a main method and call other methods
Step 6 : Stop
CODING :
import java.util.*;
class Automorphic{
int l, u;
int count;
if(n==((n*n)%Math.pow(10,d))){
return true;
}else
return false;
}
void list(){
System.out.println("Number\tSquare");
for(int i = l;i<=u;i++){
if(check(i)){
System.out.println(i+"\t"+(i*i));
count++;
}
}
System.out.println("Frequency of Automorphic Numbers between "+l+" and "+u+" is "+ count);
}
void main(){
Automorphic a = new Automorphic(1,1000);
a.list();
}
}
OUTPUT :
VDT :