AJ Java Programs
Program 4:
Disarium Number
A number will be called DISARIUM if sum of its digits powered with their respective position is equal to the original number.
For example 135 is a DISARIUM
(Workings 11+32+53 = 135, some other DISARIUM are 89, 175, 518 etc)
(Workings 11+32+53 = 135, some other DISARIUM are 89, 175, 518 etc)
Syntax:
import java.io.*;class disarium
{
public static void main(String args[])throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int n,n1,n2,c=0,sum=0,d=0;
System.out.println("Enter a Num");
n=Integer.parseInt(br.readLine());
n2=n1=n;
while(n2!=0)
{
n2=n2/10;
c++;
}
while(n1!=0)
{
d=n1%10;
sum+=Math.pow(d,c--);
n1=n1/10;
}
if(sum==n)
System.out.println(" The Number is Disarium.");
else
System.out.println("No , The Number is not disarium.");
}
}
Tested Ok Program
If You Don't Understand anything or want any program please write your request in Comment Section
And Please Like The Post
the same program in recursion method please...
ReplyDeleteSure Vandita you are our first requestee here it is http://sh.st/1l9qc
Deleteor check the blog as we updated it... ajjavaprograms.blogspot.com
PLEASE FOLLOW OUR BLOGS FOR BEING UPDATED ABOUT NEW CODES
Deletefollow codesmartjava.blogspot.com
and ajjavaprograms.blogspot.com
The encryption of alphabets are to be done as follows:
DeleteA = 1
B = 2
C = 3
.
.
.
Z = 26
The potential of a word is found by adding the encrypted value of the alphabets.
Example: KITE
Potential = 11 + 9 + 20 + 5 = 45
Accept a sentence which is terminated by either “ . ” , “ ? ” or “ ! ”. Each word of sentence is separated by single space. Decode the words according to their potential and arrange them in ascending order.
Output the result in format given below:
Example 1
INPUT : THE SKY IS THE LIMIT.
POTENTIAL : THE = 33
SKY = 55
IS = 28
THE = 33
LIMIT = 63
OUTPUT : IS THE THE SKY LIMIT
Example 2
INPUT : LOOK BEFORE YOU LEAP.
POTENTIAL : LOOK = 53
BEFORE = 51
YOU = 61
LEAP = 34
OUTPUT : LEAP BEFORE LOOK YOU
Antas Sir,Please solve two more questions.ISC-2016,Q1 and Q3 i.e non boundary element in ascending order and number of words beginning and ending with vowel.Please don't use FUNCTIONS.Every solution I saw are done using functions.I know its easy to solve with functions but still please solve without functions.
ReplyDeleteI will look at it soon and please keep requesting and promoting us "SIR"
DeleteCan't find the question paper .. please provide a link to questions or copy questions in comment or ib me
DeleteWrite a program to declare a square matrix A[][] of order (M x 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:
ReplyDelete(a) Sort the non-boundary elements in ascending order using any standard sorting technique and rearrange them in the matrix.
(b) Calculate the sum of both the diagonals.
(c) Display the original matrix, rearranged matrix and only the diagonal elements of the rearranged matrix with their sum.
Test your program with the sample data and some random data:
Example 1
INPUT :M = 4
9 2 1 5
8 13 8 4
15 6 3 11
7 12 23 8
OUTPUT:
ORIGINAL MATRIX
9 2 1 5
8 13 8 4
15 6 3 11
7 12 23 8
REARRANGED MATRIX
9 2 1 5
8 3 6 4
15 8 13 11
7 12 23 8
DIAGONAL ELEMENTS
9 5
3 6
8 13
7 8
SUM OF THE DIAGONAL ELEMENTS = 59
Write a program to accept a sentence which may be terminated by either ‘.’, ‘?’ or ‘!’ only. The words are separated with a blank space, and are in uppercase.
ReplyDeletePerform the following:
Find the number of words beginning and ending with a vowel.
Place the words which begin and end with a vowel at the beginning, followed by the remaining words as they occur in the sentence.
Test your program with the sample data and some random data:
Example 1:
INPUT: ANAMIKA AND SUSAN ARE NEVER GOING TO QUARREL ANYMORE.
OUTPUT: NUMBER OF WORDS BEGINNING AND ENDING WITH A VOWEL: 3ANAMIKA ARE ANYMORE AND SUSAN NEVER GOING TO QUARREL.
Example 2:
INPUT: YOU MUST AIM TO BE A BETTER PERSON TOMORROW THAN YOU ARE TODAY.
OUTPUT: NUMBER OF WORDS BEGINNING AND ENDING WITH A VOWEL: 2
A ARE YOU MUST AIM TO BE BETTER PERSON TOMORROW THAN YOU TODAY.
Example 3:
INPUT: LOOK BEFORE YOU LEAP.
OUTPUT: NUMBER OF WORDS BEGINNING AND ENDING WITH A VOWEL: 0
LOOK BEFORE YOU LEAP.
Example 4:
INPUT: HOW ARE YOU@
OUTPUT: Sentence must begin with ‘.’, ‘!’ or ‘?’.
Please sir find the questions above as said by you.
ReplyDeleteYou will get the code soon Sir
DeleteYou will get the code soon Sir
DeleteHere you go. Sorry for delay i was very busy but i have finished this code.
Deletesee it on my blog
Sorry Actually it is really tough to do these programs without functions , i am struck in the programs , if u allow we better use function concepts.? what say?
DeleteI agree with you.I have solved with functions.I want to know without functions.Atleast solve array question[non boundary element]without functions please if possible .
DeletePlease reply sir I required urgently.Atleast array question.
DeletePlease sir reply.
Deleteplease reply sir.
DeleteThanks a lot sir.Please solve array Question [non boundary element] + Encryption of alphabets(Given above).Please solve it as soon as possible as i required urgently.
ReplyDeletePlease solve.No reply from you side from so many days.Please refer to my request.
ReplyDeletehttp://ajjavaprograms.blogspot.in/2016/11/arranging-according-to-potential.html
ReplyDeletego ahead an check it out I found its solution.
Thanks Sir.But Please one last Question of Array.Question Given above for your reference.
DeleteWrite a program to declare a square matrix A[][] of order (M x 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:
ReplyDelete(a) Sort the non-boundary elements in ascending order using any standard sorting technique and rearrange them in the matrix.
(b) Calculate the sum of both the diagonals.
(c) Display the original matrix, rearranged matrix and only the diagonal elements of the rearranged matrix with their sum.
Test your program with the sample data and some random data:
Example 1
INPUT :M = 4
9 2 1 5
8 13 8 4
15 6 3 11
7 12 23 8
OUTPUT:
ORIGINAL MATRIX
9 2 1 5
8 13 8 4
15 6 3 11
7 12 23 8
REARRANGED MATRIX
9 2 1 5
8 3 6 4
15 8 13 11
7 12 23 8
DIAGONAL ELEMENTS
9 5
3 6
8 13
7 8
SUM OF THE DIAGONAL ELEMENTS = 59
import java.util.*;
Deleteclass SortNonBoundary_ISC2016
{
int A[][],B[],m,n;
void input() //Function for taking all the necessary inputs
{
Scanner sc = new Scanner(System.in);
System.out.print("Enter the size of the square matrix : ");
m=sc.nextInt();
if(m<4 || m>10)
System.out.println("Invalid Range");
else
{
A = new int[m][m];
n = (m-2)*(m-2);
B = new int[n]; //Array to store Non-Boundary Elements
System.out.println("Enter the elements of the Matrix : ");
for(int i=0;iB[j])
{
c = B[i];
B[i] = B[j];
B[j] = c;
}
}
}
}
void printArray() //Function for printing the array A[][]
{
for(int i=0;i<m;i++)
{
for(int j=0;j<m;j++)
{
System.out.print(A[i][j]+"\t");
}
System.out.println();
}
}
void printDiagonal() //Function for printing the diagonal elements and their sum
{
int sum = 0;
for(int i=0;i<m;i++)
{
for(int j=0;j<m;j++)
{
if(i==j || (i+j)==m-1)
{
System.out.print(A[i][j]+"\t");
sum = sum + A[i][j];
}
else
System.out.print("\t");
}
System.out.println();
}
System.out.println("Sum of the Diagonal Elements : "+sum);
}
public static void main(String args[])
{
SortNonBoundary_ISC2016 ob = new SortNonBoundary_ISC2016();
ob.input();
System.out.println("*********************");
System.out.println("The original matrix:");
System.out.println("*********************");
ob.printArray(); //Printing the original array
ob.convert(1); //Storing Non-Boundary elements to a 1-D array
ob.sortArray(); //Sorting the 1-D array (i.e. Non-Diagonal Elements)
ob.convert(2); //Storing the sorted Non-Boundary elements back to original 2-D array
System.out.println("*********************");
System.out.println("The Rearranged matrix:");
System.out.println("*********************");
ob.printArray(); //Printing the rearranged array
System.out.println("*********************");
System.out.println("The Diagonal Elements:");
System.out.println("*********************");
ob.printDiagonal(); //Printing the diagonal elements and their sum
}
}
Found that on Google
DeleteSir can it be done without functions if possible.If not then thanks.But still i thought you can do without functions.
ReplyDeleteSir please one last question.Can it be done without function.Please solve without functions[array non boundary].
ReplyDeleteTq
ReplyDelete