Skip to main content

Disarium Number

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)

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

Comments

  1. the same program in recursion method please...

    ReplyDelete
    Replies
    1. Sure Vandita you are our first requestee here it is http://sh.st/1l9qc
      or check the blog as we updated it... ajjavaprograms.blogspot.com

      Delete
    2. PLEASE FOLLOW OUR BLOGS FOR BEING UPDATED ABOUT NEW CODES
      follow codesmartjava.blogspot.com
      and ajjavaprograms.blogspot.com

      Delete
    3. The encryption of alphabets are to be done as follows:

      A = 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

      Delete
  2. 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.

    ReplyDelete
    Replies
    1. I will look at it soon and please keep requesting and promoting us "SIR"

      Delete
    2. Can't find the question paper .. please provide a link to questions or copy questions in comment or ib me

      Delete
  3. Write 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:

    (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

    ReplyDelete
  4. 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.

    Perform 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 ‘?’.

    ReplyDelete
  5. Please sir find the questions above as said by you.

    ReplyDelete
    Replies
    1. You will get the code soon Sir

      Delete
    2. You will get the code soon Sir

      Delete
    3. Here you go. Sorry for delay i was very busy but i have finished this code.
      see it on my blog

      Delete
    4. 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?

      Delete
    5. I 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 .

      Delete
    6. Please reply sir I required urgently.Atleast array question.

      Delete
  6. Thanks 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.

    ReplyDelete
  7. Please solve.No reply from you side from so many days.Please refer to my request.

    ReplyDelete
  8. http://ajjavaprograms.blogspot.in/2016/11/arranging-according-to-potential.html

    go ahead an check it out I found its solution.

    ReplyDelete
    Replies
    1. Thanks Sir.But Please one last Question of Array.Question Given above for your reference.

      Delete
  9. Write 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:

    (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

    ReplyDelete
    Replies
    1. import java.util.*;
      class 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
      }
      }

      Delete
  10. Sir can it be done without functions if possible.If not then thanks.But still i thought you can do without functions.

    ReplyDelete
  11. Sir please one last question.Can it be done without function.Please solve without functions[array non boundary].

    ReplyDelete

Post a Comment

Popular posts from this blog

Arranging according to potential.

PROGRAM: Requested by Sir  Ankur Acharya   ARRANGING WORDS IN A STRING ACCORDING TO THEIR POTENTIAL The encryption of alphabets are to be done as follows: A = 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 SYNTAX import java.io.*; class Potential {     public static void main(String args[])throws IOException     {         BufferedReader br=new BufferedReader(new Inp

SMITH NUMBER

PROGRAM: SMITH NUMBER A   Smith number  is a composite number, the sum of whose digits is the sum of the digits of its prime factors obtained as a result of prime factorization (excluding 1). The first few such numbers are 4, 22, 58, 85, 94, 121 ……………….. For Example 58=> 5+8=13 2+(2+9) of 29 =13 Since sum of digits=sum of digits of prime factors 58 is a SMITH NUMBER SYNTAX: import java.io.*; class smith_no { static int sum,sum1;     public static void main(String args[])throws IOException     {         BufferedReader br=new BufferedReader(new InputStreamReader(System.in));         int n;int c=0;         System.out.println("Enter a Number");         n=Integer.parseInt(br.readLine());         int n1=n;         while(n1!=0){         int d=n1%10;         sum1+=d;         n1=n1/10;}         for(int i=2;i<n;i++)         {             if(n%i==0)             {                 for(int j=2;j<i;j++)                 {                     if(i

MAGICAL/ MAGIC NUMBER USING RECURSION

PROGRAM :  MAGICAL NUMBER BY RECURSION This  program  checks if a  number  is a  Magic number  in  JAVA . A  number  is said to be a  Magic number  if the sum of its digits are calculated till a single digit is obtained by recursively adding the sum of its digits. If the single digit comes to be 1 then the  number  is a  magic number . Example: 10999 => 1+0+9+9+9=28=>2+8=>10=>1+0= 1                  199    =>1+9+9 =>19=> 1+9=>10=>1+0= 1 SYNTAX import java.io.*; class magic  {    static int c;     public static void main(String arsg[])throws IOException     {         BufferedReader br=new BufferedReader(new InputStreamReader(System.in));         int n;int d=0;int m;         System.out.println("ENter a NUmber");         n=Integer.parseInt(br.readLine());         m=n;         while(n!=0)         {d=n%10;             n=n/10;             c++;         }         magical(m);              }     public static void magical(int x)